all groups > flash actionscript > february 2006 >
You're in the

flash actionscript

group:

TextInput inside Class


TextInput inside Class l810c
2/28/2006 7:43:54 PM
flash actionscript:
I've seen this asked a couple dozen times in various places, but have never
seen an answer.

I start the app, then click a button that calls my premade form with this:
createEmptyMovieClip("register1_mc", 20002);
register1_mc.attachMovie("register_mc", "register2_mc", level, {_x:150,
_y:50});

The form/movie has Profile as it's AS2.0 class.

Then it get bizarre.

Here's my output with notes:

txtFirst_Name.text #1 : undefined // Not yet available in the constructor

sText : ABC123 // Everything thing looks great here when I call this via the
doLater function. I set and get the .text for my TextInput
txtFirst_Name.text #2 : ABC123 //This value also shows up in the TextInput on
the screen

fillinfo : undefined //These 2 lines generated when I enter 2 characters in my
TextInput. The change event listener works great for my TextInput
fillinfo : undefined // But it can't find it's own .text value. It is not
undefined, it right there on my screen with ABC123 in it!?!?

Register // When I click my Register button it still cannot find the .text of
my TextInput
txtFirst_Name.text #3 undefined

Also, why does this function not get called from within my Register function?
this.FillText();




import mx.core.UIObject;
import mx.controls.Button;
import mx.controls.TextInput;

class Profile extends UIObject {

private var txtFirst_Name:TextInput;
private var txtLast_Name:TextInput;
private var but_register:Button;
private var cancel1_btn:Button;
private var txtAst1:TextField;
private var keyListener:Object = new Object();
private var _sAddUpdate:String;


private var dispatchEvent:Function;
public var addEventListener:Function;
public var removeEventListener:Function;

function Profile() {
Selection.setFocus("txtFirst_Name");
doLater(this, "addListeners");
doLater(this, "FillText");
}

function Enter() {
switch (Key.getCode()) {
case Key.ENTER :
Register();
break;
}
};

function addListeners() {
but_register.addEventListener("click", Register);
cancel1_btn.addEventListener("click", Cancel);
txtFirst_Name.addEventListener("change",fillInfo)
}

function fillInfo() {
trace("fillinfo : " + this.txtFirst_Name.text);
}

function updateProfile(x:Number) {
trace("UPDATE " + x);
}

function Cancel() {
Key.removeListener(keyListener);
unloadMovie(this._parent);
unloadMovie(this);
};

function Register() {
trace("Register");
this.FillText();
txtFirst_Name.text = "ABCDEFG";

trace("txtFirst_Name.text" + txtFirst_Name.text);
if (txtFirst_Name.text == "") {
mx.controls.Alert.show("Please Enter First Name");
Selection.setFocus("txtFirst_Name");
}
else if (txtLast_Name.text == "") {
mx.controls.Alert.show("Please Enter Last Name");
Selection.setFocus("txtLast_Name");
}
else {
//Register Code
}

}


function FillText() {
var sText:String;
sText = "ABC123";
trace("sText : " + sText);
txtFirst_Name.text = sText;
trace("txtFirst_Name.text : " + txtFirst_Name.text);
}


function SetTabs() {
txtFirst_Name.tabIndex = 1;
txtLast_Name.tabIndex = 2;
but_register.tabIndex = 3;
cancel1_btn.tabIndex = 4;
}

}
Re: TextInput inside Class blemmo
2/28/2006 11:53:19 PM
Yeah... Flash code execution order strikes again ;)
First it executes all the code in a frame, then the code in (just created)
children MCs. I think that may be the issue here...
It means if you create that class in the first frame of your register_mc, this
code will not execute until all code from the parent frame is done. So you may
set some values in the child MC from the parent frame, but the associated
functions/listeners will not work yet. Do it in the next frame, and it should
work fine.

hth,
blemmo
Re: TextInput inside Class l810c
3/8/2006 12:46:13 AM
Revisited this after moving on for a while.

The problem is the reference to 'this'. It returns a reference to the object
that has an event triggered instead of the class.

txtFirst_Name.addEventListener("change",fillInfo)

This returns undefined:
function fillInfo() {
trace("fillinfo : " + this.txtFirst_Name.text);
}

I tried this, but it would not compile: (There is no property with the name
'text')
function fillInfo() {
trace("fillinfo : " + this.text);
}

This one works:
function fillInfo() {
trace("fillinfo : " + this._parent.txtFirst_Name.text);
}


AddThis Social Bookmark Button