Link to home
Start Free TrialLog in
Avatar of john_yourspace
john_yourspace

asked on

AS 3 Eval

Hi guys,

I am trying to populate some text fields using this

public var txtName:String ="MovieClip(leaderboard).txtName";
		public var pic:String ="MovieClip(leaderboard).pic";
		public var txtTime:String ="MovieClip(leaderboard).txtTime";
		
		public function popLeaderBoard() : void {
			
			var currentVO:Number = 0;
			
			for each (var scoreVO:Object in leaderBoardDecoded) 
			{
				currentVO++;
				
				var leaderPic = "http://graph.facebook.com/"+scoreVO.fbname+"/picture";
				var leaderPicFile : DisplayObject = loadSmallFBPic(facebookpic);
				
				txtName = "leaderboard.txtName"+currentVO +".text";
				pic = "MovieClip(leaderboard).pic"+currentVO;
				txtTime = "MovieClip(leaderboard).txtTime"+currentVO;

				
				this[txtName]= scoreVO.fname;
				//this[pic].removeChildAt(0);
				//this[pic].addChild(leaderPicFile);
				//this[txtTime].text= scoreVO.scoreTime;
			
			
			}
			
			

		};

Open in new window



So i am looping the VO and getting the values fine however I need to dynamically get access to the text field , txtName1 -> txtName10.

John
ASKER CERTIFIED SOLUTION
Avatar of Antonio Estrada
Antonio Estrada
Flag of Mexico image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of john_yourspace
john_yourspace

ASKER

Hi V,

Tried that got this


       tmpTxtField = TextField(this.getChildByName("leaderboard.txtName" + currentVO));
       tmpTxtField.text = scoreVO.fname;

Cannot access a property or method of a null object reference.

Your code above gave a coercion error

Symbol 'Leaderboard', Layer 'AS', Frame 1, Line 22      1118: Implicit coercion of a value with static type flash.display:DisplayObject to a possibly unrelated type flash.text:TextField.
Well, apparently the object "leaderboard.txtName0" (and txtName1, etc) are in fact MovieClips and not TextFields, is there a TextField within that MovieClip maybe? if so, that's the one who should be called.

Or you can post your files and I'll take a look at them.

Good luck

-V
Thanks V, you sent me in the right direction

This worked

TextField(leaderboard.getChildByName("txtName" + currentVO));


var currentVO:Number = 0;
			for each (var scoreVO:Object in leaderBoardDecoded) 
			{
				currentVO++;

				var tmpTxtField:TextField = TextField(leaderboard.getChildByName("txtName" + currentVO));
				tmpTxtField.text = scoreVO.fname + " " + scoreVO.lname;
				
				var tmpScoreTxtField:TextField = TextField(leaderboard.getChildByName("txtTime" + currentVO));
				tmpScoreTxtField.text = scoreVO.scoreTime;
				
				var leaderPic = "http://graph.facebook.com/"+scoreVO.fbname+"/picture";
				var leaderPicFile : DisplayObject = loadSmallFBPic(leaderPic);
				
				var tmpPicField:* = leaderboard.getChildByName("pic" + currentVO);
				tmpPicField.removeChildAt(0);
				tmpPicField.addChild(leaderPicFile);

			}

Open in new window

Glad to help!

-V