;

PDA

Click to See Complete Forum and Search --> : reference textfield on timeline


nielzzz
02-22-2009, 10:02 AM
In de Flash IDE I create this movieclip 'MC1' and assign class MC1.as to it.

On the timeline, I add a textfield 'TF1'.

Now, in MC1.as I can change the textfield easily: TF1.text = 'text here'.

This works perfectly and I should not complain... however;

Is there a way I can tell my class MC1.as that there is a TF1 that is a textfield? So I can use codehinting?

If I add

var TF1:TextField;

the reference to the textfield is lost and now NULL. So that does not work.

neznein9
02-23-2009, 09:18 AM
You can create a variable for it but you'll hit the code-before-stage problem. Basically your class constructor can be run at "frame -1" so that everything is set up properly before everything is added into the display list...to work around that you need to wait until the display items are all added before you grab the reference to the textfield.


public var TF1:TextField;

// constructor
public function MC1(){
addEventListener(Event.ADDED_TO_STAGE, function(e:Event):void{
removeEventListener(Event.ADDED_TO_STAGE, arguments.callee);
TF1 = TextField(getChildByName('TF1'));
});
}