Frame scripts in Actionscript 3.0?

By atksheu | Jul 4, 2009

actionscript3

Hi,

Happy 4th and all! My question relates the use of frame scripts in the flash authoring environment and if it is possible to easily exchange instance methods and variables between frame scripts and scripts defined in classes externally.

A simplified scenario of what I am trying to do is this:

In the first frame of my .fla file, on the actions layer, I’ve written the script:

var testString:String = "Welcome";

In my document class named "Body", inside its constructor, I’ve written:

trace(testString);

The resulting compiler error is as follows:

TypeError: Error #1009: Cannot access a property or method of a null object reference.
at Body$iinit()

Does that mean that the variable hasn’t been instantiated yet? If that’s the problem, and the constructor is executing before the variable has been defined in the frame script, does anyone know of a way to remedy that? I’ve tried placing the trace command at different points in my classes, after the frame script should surely have been executed.

I’ve looked at various other threads that have touched on this issue, but nothing describes this questions exactly. I’m pretty sure that this sort of variable and methods exchange between the timeline and classes should be possible. This is excerpted from the O’Reilly Colin Moock book, Chapter 29 under section label "Variable and Function Definitions in Frame Scripts.":

"A variable definition in a frame script on a .fla file’s main timeline creates an instance variable in that .fla file’s document class. Likewise, a function definition in a frame script on a .fla file’s main timeline creates an instance method in that .fla file’s document class.

Similarly, a variable definition in a frame script on a Movie Clip symbol’s timeline creates an instance variable in the symbol’s linked class. And a function definition in a frame script on a Movie Clip symbol’s timeline creates an instance method in the symbol’s linked class."

So presumably, frame scripts are as legitimate way to define variables and methods as one contained within classes.

Also, if anyone would care to provide a bigger picture for me, are frame scripts generally frowned upon, now. This thread linked here (http://www.actionscript.org/forums/a…/t-135760.html) seemed to suggest that there should only be Actionscript in the Flash Authoring Environment on the first frame of the main timeline, if at all. My goal, that this currently problem is tied to, is to make a website, based on the Flash program’s timeline and animation behaviors. I’m having trouble constructing the architecture of the coding through only classes.

Thanks a lot

actionscript3

Please reply at our Forum

Leave a Comment

If you would like to make a comment, please fill out the form below.

Name (required)

Email (required)

Website

Comments

© 2007 ActionScript 3.0