Learned about a promising library for Actionscript 3 today, Casalib. There will be more information about the library, as I’m just starting to get to playing with it.
Something that has been pissing off recently, has been the lack of ability to easily reference the stage from any object in AS3. I find myself building controllers to manage objects in the stage, and I have to play tricks with passing objects around. Why I haven’t written a class to access the stage is beyond me.
In looking at the blog for Casalib, I saw a post Get Access to the Stage Wherever You Need It.
I’ll quote the article below:
In ActionScript 2, it was possible to access the stage from anywhere, through the static Stage class. With ActionScript 3, we lost that ability, and only display objects were permitted access—and only once they had been added to the stage.
To help you get access wherever you need it, CASA Lib for AS3 has a utility class called
org.casalib.utilpackage. It’s a static class that lets you keep track of the stage (or multiple stages if you’re developing an AIR app with multiple windows). Here’s how we recommend using it.
In the constructor of your main document class, just call this line of code:StageReference.setStage(this.stage);
Now, throughout your entire site or application, you can get access to the stage reference from anywhere by using this line of code:StageReference.getStage();