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
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!
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
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;
}
}
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
Sam