1
votes

I'm using Flash CS3 and ActionScript 2. I have a MovieClip symbol (identified as "MySymbol") that contains a dynamic text block with the identifier "innerText". The symbol is marked as "Export for ActionScript" using the following "MySymbol.as" file:

class MySymbol extends MovieClip
{
        function SetText(text)
        {
                innerText.text = text;
        }
}

In the frame actions, I tried doing the following:

var symInst = _root.attachMovie("MySymbol", "MySymbol" + _root.getNextHighestDepth(), _root.getNextHighestDepth());
symInst.SetText("hi");  // Fails
symInst.innerText.text = "hi";  // Works

I get the compile error:

There is no property with the name 'innerText'.

Why is it that I can access the innerText from the frame actions, but not reference it within the .as file itself?

2

2 Answers

2
votes

You are getting a compiler error because "innerText" is not available to the class at compile time (i.e. it's available at runtime).

A quick fix is to use

this['innerText'].text = text;

instead of

innerText.text = text;
1
votes

I'm guessing that the TextField "innerText" was created using the Text tool in Flash CS3. If that's the case, then the compiler knows about it to some degree because it needs to take the information from the .FLA file about what elements it needs to create on the stage, or what symbols it needs to place in the Library.

To access that property from your class, you need to define a variable for it in your class, even though it's technically part of that MovieClip.

Try modifying your class like this:

class MySymbol extends MovieClip

{

    private var innerText:TextField;

    function SetText(text)
    {
            innerText.text = text;
    }

}

By adding the declaration for innerText in the class, the compiler will know for sure what it's looking for vs. assuming the property exists, like it would with this['innerText']. (Though that's still a valid way of accessing that property.