Archive for the flash Category

Storing SWFObject.addVariable() vars globally in AS3

Embedding variables with SWFObject is easy. In previous versions of Actionscript all the variables registered with the SWFObject were globally available within the SWF. From any class or object, you could call _root.theVariableName and access that variable.

However, moving to AS3, things are a little different. The SWFObject still embeds FlashPlayer 9 content without a problem – the SWF is properly embedded into the HTML and all the variables and parameters passed to the SWFObject are registered with the SWF. The only difference in AS3 is that these variables are not automatically available throughout your FLA.

Continue reading Storing SWFObject.addVariable() vars globally in AS3

SWFAddress: Extending and Adding to a framework

In my last SWFAddress post, I called for all flash developers big and small to consider using SWFAddress in their upcoming projects. I dont want to just preach afterall, so I created a basic example project.

Since most of the Flash sites I build at visicswire use a small framework of custom components, my approach to incorporating SWFAddress into projects is to register my navigation components with the SWFAddress. I have also tweaked the SWFAddress source code slightly to add a handy method (will explain below).

Continue reading SWFAddress: Extending and Adding to a framework

SWFAddress: USE IT!

Making your Flash project utilize the back/forward browser buttons used to be a pain…. years ago. Making your project deep-linkable used to be a pain…. years ago. Tracking your user’s traffic through your Flash project used to be a pain…. years ago. There are no more excuses.

SWFAddress has been around for a while, and its a little a dissapointing to see new, all-Flash projects being released without incorporating browser button and deep-linking support. If you are interested in using SWFAddress, check out the SWFAddress site to download it and check out the example project.

It relies on your project being embedded with the SWFObject, which you are hopefully using anyway. An added bonus: add the google analytics urchin to your project and you will be able to track all changes to the hash of your URL (your users’ navigation through your SWF)

Global Variables in AS3

EDIT — 09/03/09 I decided to update this article in response to some of the comments about the potential dangers of using global properties. Its a convenient way to store variables that are accessible from anywhere in your project, but with great power comes great responsibility :).

Yes, we know it can get sloppy, but sometimes is just makes sense to create variables that are accessible from anywhere in your project.

Prior to AS3 it was really easy… there was the _global object: _globals.myvar = 'mystring'. You are most likely reading this because you are trying to use the _global object in AS3. Ecmascript (the standard on which AS3 is based) does not support this notion, rather it forces you to create your own globally accessible object if you so desire. They are encouraging instance based data coupling, because it’s a lot more structured and less error prone. If you are working on a large application, I will encourage you to not use global variables (especially if unit testing is a requirement). However, if you don’t give a damn about what us programming snobs say, have no idea what unit testing is, or just want to use some global variables in AS3, then don’t feel bad, they can be quite handy!

Continue reading Global Variables in AS3

onReleaseOutside in AS3 using DisplayObject.stage.addEventListener

I am working a few basic wrapper classes for my AS3 library. I am essetially using the Decorator pattern to wrap display objects with, for example, draggable resizing functionality. As I was creating my ResizableSprite class, I came to a point where the onReleaseOutside event of old would have really come in handy.

Needless to say, onReleaseOutside is no longer an event in AS3. Simple enough to get around, right? Can’t we just set a MouseListener to check for MouseUp event? The answer, depending on your Actionscript background is both yes and no. In AS2 the Mouse object was global, meaning that any line of code in the application (no matter what frame, object, class, etc… it was written in) that referenced the Mouse object all talked to the same object. Things have changed in AS3; each Display Object (SimpleButton, Sprite, MovieClip, TextField… basically anything drawn on the stage) has its own internal Mouse object, that only reacts when the mouse is over that object. So, in the case of onReleaseOutside, clicking on the object will trigger an event, moving off that object will trigger an event, but releasing the mouse off of the object will be ignored and won’t fire an event.

Continue reading onReleaseOutside in AS3 using DisplayObject.stage.addEventListener