Search code examples
actionscript-3actionscriptreferenceflash-cs4

How to refer to object from next frame AS3


I've problem with Flash CS4. I've TextFields on first frame, and other TextFields on second frame, etc. And at first frame I've TextField to puting number, and button Calculate, which calculate value to all TextField. And I've menu to navigate throught the tabs (frames).

So... when I put number and click Calculate I get values at TextFields at first frame, but when I switch to next tab (frame) I see clear TextFields and error at output (Error #1009).

I know, that reason is add values in first frame to TextFields from next frames, but I don't know how I can fix it.

Please for help.


Solution

  • When the next tab is clicked, store the value of the textfield in a variable.

    If writing your ActionScript on the timeline, this is the code:

    // On frame 1:
    // Create the variable to store the textfield value
    textfieldValue:String = "";
    
    function tabClicked(event:MouseEvent):void {
        // Store the value of myTextField
        textfieldValue = myTextField.text;
    }
    
    // On frame 2
    // Populate the new instance of myTextField with the stored value
    myTextfield.text = textfieldValue;