PDA

View Full Version : Classes and symbols


roscoman
07-18-2006, 10:26 AM
OK
I have made a MovieClip called fred with a dynamic text field in it, the text field is called myText.

I have made a class like this:

class FredClass extends MovieClip
{
public function FredClass() {}

public function changeText(newText)
{
myTextField.text = newText;
}

public function changeFrame(newFrameNumber)
{
gotoAndStop(newFrameNumber);
}

}

Then I update the appropriate linkage properties of the fred symbol to link it to the class. Then I place an instance of fred on the main stage and call it aFredInstance. I can tell that all this works because I can successfully call the changeFrame() function and that works.

However, if I try to change the text in the text field using:

_root.aFredInstance.changeText("some new text");


I get the following error:

There is no property with the name 'myTextField'.
this.myTextField.text = newText;

What am I doing wrong? How do I access objects within the symbol and change their properties?

Many thanks
Ross

mooska
07-18-2006, 10:32 AM
class FredClass extends MovieClip
{
var myTextField:TextField;
public function changeText(newText)
{
this.myTextField.text = newText;//put it like that, but it has no meaning in your prob, just a note
}
}

roscoman
07-18-2006, 10:37 AM
Mooska, you deserve a medal :) Thank you so much

mooska
07-18-2006, 10:40 AM
email me one :D
gold, silver will do.

mooska