Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

refer to a TextField in a class

0 views
Skip to first unread message

InsAnimal

unread,
Mar 16, 2004, 8:45:52 AM3/16/04
to
How can I refer to a textfield from inside a class?

putting it on the stage inside the Movieclip the class is for and referring by
the instance name doesn't work,
and neither does using the movieclip's createTextField method - referring by
the instance name set by the method
doesn't work and unfortunately createTextField doesn't return a reference to
the object.

What am I missing?

Sam

MOLOKO

unread,
Mar 16, 2004, 9:01:07 AM3/16/04
to

dunno, have never had a problem with this. perhaps posting some code
might help us find out? you don't even state which version of flash you
are using!

if it helps, the following code (Flash MX style AS) works fine....
You'll need two buttons inside the movieclip, with instance names of
'hide_btn' and 'show_btn'

#initclip

function MyClip()
{
trace("MyClip Class :" + this.textstr);
this.createTextField("mytext_txt",1,0,0,200,50);
this.mytext_txt.text = this.textstr;
this.hide_btn.onRelease = this.hideText;
this.show_btn.onRelease = this.showText;
}
MyClip.prototype = new MovieClip();
MyClip.prototype.hideText = function()
{
//NB this method is assigned to a button so any
//paths must be relative to the button, hence
//the use of '_parent'
this._parent.mytext_txt._visible = false;
}
MyClip.prototype.showText = function()
{
this._parent.mytext_txt._visible = true;
}
Object.registerClass("myclip",MyClip);

#endinitclip

//attach clip to stage thusly:
this.attachMovie("myclip","clip_mc",2,{textstr:"this is some text"});
--
MOLOKO
------------------------------------------------
::remove _underwear_ to reply::
'God saves but Buddha makes incremental backups'
------------------------------------------------
GCM/CS/IT/MC d-- S++:- a- C++ U--- P+ L++ !E W+++$ N++ O? K+ w+++$ !O M+
VMS? PS+++ PE- Y PGP+ t+ 5-- X-- R* tv++ b++++ DI++++ D+ G e h-- r+ y++
see www.geekcode.com to translate the above!

InsAnimal

unread,
Mar 16, 2004, 2:37:34 PM3/16/04
to
My apologies, I am using Flash MX 2004.

I have tried three different ways :

1) I have a class defined as follows saved as MyButton.as :

class MyButton extends MovieClip
{
function MyButton()
{
}

public function set displayedText( value:String )
{
this.Button_txt.text = value;
}

}

And on the stageof my .fla I have a Movieclip which I have linked to that
class via the linkage properties
for the symbol in the library. Inside the symbol I have placed a dynamic
textfield with the instance
name Button_txt

2) I have a class defined as follows, with no textfield as a child of the
symbol.

class MyButton extends MovieClip
{
function MyButton()
{
this.createTextField( "Button_txt", this.getNextHighestDepth(), 0, 0,
50, 30 );
}

public function set displayedText( value:String )
{
this.Button_txt.text = value;
}

}

In both 1) and 2) cases I get the following error:

Line 10: There is no property with the name 'Button_txt'.
this.Button_txt.text = value;

3) The annoying thing is that if createTextField returned a reference to the
object it creates,
as I think it should, I could refer to it that way. But this class:

class MyButton extends MovieClip
{
private var MyText_txt:TextField;

function MyButton()
{
this.MyText_txt = this.createTextField( "Button_txt",
this.getNextHighestDepth(), 0, 0, 50, 30 );
}

public function set displayedText( value:String )
{
this.MyText_txt.text = value;
}

}

gives me the error
Line 7: Type mismatch in assignment statement: found Void where TextField is
required.
this.MyText_txt = this.createTextField( "Button_txt",
this.getNextHighestDepth(), 0, 0, 50, 30 );

Any ideas would be greatly appreciated!

Sam

Flinchvoid

unread,
Mar 16, 2004, 2:57:54 PM3/16/04
to
Try this...

class MyButton extends MovieClip {

// you must declare Button_txt as a class member to access it

private var Button_txt : TextField = null;

function MyButton() {

};

public function setDisplayedText( value:String ) {
// once the clip has loaded, the class member Button_txt will reference the
textfield of the same name
Button_txt.text = value;
}

}

InsAnimal

unread,
Mar 16, 2004, 2:54:09 PM3/16/04
to
Never mind, I found an answer here! :

http://www.macromedia.com/cfusion/webforums/forum/messageview.cfm?catid=288&thre
adid=768080&highlight_key=y&keyword1=There%20is%20no%20property%20with%20the%20n
ame

It seems if I refer to it as this["Button_txt"].text instead of
this.Button_txt.text it works just fine!

however I still don't understand why createTextField doesn't return a
reference :)

Thanks anyway

Sam

InsAnimal

unread,
Mar 18, 2004, 8:48:04 AM3/18/04
to
Thankyou Flinchvoid, your way works equally well whether I place the textfield on the
movieclip's stage by hand or if i do it using createTextField()

Sam

0 new messages