Groups | Blog | Home
all groups > flash actionscript > february 2006 >

flash actionscript : Dynamic TextField in class


l810c
2/8/2006 9:21:37 PM
....my traces print

undefined
undefined
Clear._x undefined



class Loader extends MovieClip{
public function Loader() {
var Clear:TextField = this.createTextField("Clear", 500, 30, 30, 50, 20);
Clear.text = "Clear";
Clear._x = 60;
trace(Clear._width);
trace(Clear.text);
trace("Clear._x " + String(Clear._x));
}
}
Rothrock
2/8/2006 9:59:17 PM
Because if you check the help entry for createTextField you will find that it
doesn't return a reference to the newly created text field?

That would be my guess. You are expecting it to work like
createEmptyMovieClip, but I don't think it does.
LuigiL
2/9/2006 12:00:00 AM
Rothrock is correct. createTextField() doesn't return anything. So your code
should look like:

class Loader extends MovieClip{
public function Loader() {
this.createTextField("Clear", 500, 30, 30, 50, 20);
this.Clear.text = "Clear";
this.Clear._x = 60;
trace(this.Clear._width);
trace(this.Clear.text);
trace("Clear._x " + String(this.Clear._x));
}
}
l810c
2/9/2006 3:19:32 PM
createEmptyMovieClip behaves the same way. Again I get:
undefined
mc._x undefined

This all works in a regular Flash file. I've been using it for months. I'm
trying to make the move to classes and everything's breaking.



class Loader5 extends MovieClip{
public function Loader5() {
var mc:MovieClip = createEmptyMovieClip("mc", 200);
trace(mc._x);
trace("mc._x " + String(mc._x));
}
}
l810c
2/9/2006 3:21:32 PM
Originally posted by: LuigiL
Rothrock is correct. createTextField() doesn't return anything. So your code
should look like:

class Loader extends MovieClip{
public function Loader() {
this.createTextField("Clear", 500, 30, 30, 50, 20);
this.Clear.text = "Clear";
this.Clear._x = 60;
trace(this.Clear._width);
trace(this.Clear.text);
trace("Clear._x " + String(this.Clear._x));
}
}



**Error** Line 4: There is no property with the name 'Clear'.
this.Clear.text = "Clear";

**Error** Line 5: There is no property with the name 'Clear'.
this.Clear._x = 60;

**Error** Line 6: There is no property with the name 'Clear'.
trace(this.Clear._width);

**Error** Line 7: There is no property with the name 'Clear'.
trace(this.Clear.text);

**Error** Line 8: There is no property with the name 'Clear'.
trace("Clear._x " + String(this.Clear._x));

Total ActionScript Errors: 5 Reported Errors: 5
LuigiL
2/9/2006 3:32:27 PM
class Loader extends MovieClip{
private var Clear:TextField;
public function Loader() {
this.createTextField("Clear", 500, 30, 30, 50, 20);
this.Clear.text = "Clear";
this.Clear._x = 60;
trace(this.Clear._width);
trace(this.Clear.text);
trace("Clear._x " + String(this.Clear._x));
}
}
l810c
2/9/2006 4:34:21 PM
Thanks

AddThis Social Bookmark Button