At work I am making a new Flash interface for a project, and my goal this time around was to make as many global functions out of repetitive ones as possible so we could save development time.
As I began writing and testing Prototype class extensions and global functions, I noticed something I had not run into before with flash. If Import classes on one ActionScript layer, and call it on another Actions layer, or even the next frame, it produces an ActionScript error.
Normally, I put all actions and functions on one layer and have no keyframes unless they are inside other MovieClips, or I need to animate something to audio cues. With this current project, there was going to be so much ActionScript, I decided to do more than one Actions layer so I could keep everything straight. Never having a reason to do this until now, I was not prepared for some of the problems I ran into. First and foremost being that: If import a class on one Actions layer, and I create a new class object from that group on another layer, I get a syntax error.
Here is a quick example. I have a MovieClip named “box1” and I am going to tween it with the Tween class. normally I would just put it all on the same layer like this:
import mx.transitions.Tween; import mx.transitions.easing.*; var boxTween:Tween = new Tween(box1, "_x", Regular.easeOut, box1._x, box1._x+300, 1, true);
This works perfectly and makes the box move across the screen on load. When I ran into the error was when I decided that I wanted all imports on one actions layer and the object on another. Like so:
I expected it to work just the same, as I have My publish settings set to ActionScript 2.0, top down, and Flash 8. Instead, I was presented with a nice error.
The problem is replicated also by putting the new Tween object in the following frame. Effectively, any frame that ISN’T the one I imported the class into. This strikes me as totally odd, as functions endure over frames and from layer to layer. I also tested this with other import classes besides the Tween class. I had the same issues with the Alert class and BitmapData class.
For now, the simple solution I came up with was making a function in the same frame/layer as the import classes that I would simply call elsewhere when I needed the tween to happen. This of course makes no sense to me at all, but it works perfectly.
import mx.transitions.Tween; import mx.transitions.easing.*; function tweenIt() { var boxTween:Tween = new Tween(box1, "_x", Regular.easeOut, box1._x, box1._x+300, 1, true); }
Calling this function in other frames and layers has worked so far, and has more than solved my problem. If you are using multiple tweens, or classes, you could use passthrough variables to be able to make the function usable in other situations.
import mx.transitions.Tween; import mx.transitions.easing.*; function tweenIt(mc:MovieClip):Void { mc.boxTween = new Tween(mc, "_x", Regular.easeOut, mc._x, mc._x+300, 1, true); } tweenIt(box1)
If I found out any more info as to why this is a problem, I will post it here. If anyone else has some insight, please leave me a comment.




Page 1 of 1 pages
Previous entry: Dreamweaver Mass Find Replace Extension | Next entry: Expression engine 1.6 Preview and Rick Ellis Birthday Contest