How can I transfer code inside of a symbol in Flash to my document class?

55 Views Asked by At

I am pretty new to coding in general so I'll admit my understanding of inheritance is poor. I have this code that works when it's embedded in a symbol in my Fla doc, but I can't figure out how to transfer it to the Main document.

stop();
stage.focus = input_txt;
var outputText:String;   
input_txt.visible = true;
input_txt.addEventListener(KeyboardEvent.KEY_DOWN, pressEnter);

function pressEnter(e:KeyboardEvent):void {

if(e.charCode == 13) {
    captureText();
    this.nextFrame();
    }   
}

function captureText():void {
outputText=input_txt.text;
}     

All that code occurred on frame2 of the office_mc symbol, and then frame 3 has this: output_txt.text = outputText;

I'm aware that I needed to reference the txt objects as office_mc.input_txt inside the main document since they are embedded. I'm also aware that outputText would need to be a global variable. But no matter how I tried to move things around I kept having an error due to something being null. For a little background information, I'm just trying to have user input displayed in a different area within this symbol.

Could someone explain or give an example of how to execute this code in a document class? Also I'm just totally confused about how to communicate between classes in general so if anyone could point me towards tutorials or example code that could help with that understanding, it'd be greatly appreciated. :)

1

There are 1 best solutions below

0
On

Don't code in timeline at all (this is a good practice).

You should use only classes which eventually points to objects from the timeline.

Here you have some good tutorials: