I’ve been playing around with some strange ActionScript behaviour I discovered a while back. In search for the ultimate “infinite loop” I had a SWF load itself into a level and what do you know, with a little bit of tweaking we’ve created ourselves a new level.
I only tested it on Flash MX for the time being though I have some indications that it also works on MX 2004. It appears that the newly created level can only be used to store variables, things like onEnterFrame don’t work on it. Also good to note is that any movieclip assets you might have on _level0 are *not* loaded into this higher level so you don’t have duplicate assets.
I have no idea why you would use this and certainly wouldn’t recommend it as good coding practice though it’s an interesting piece of code to say the least. One question does remain: why does this work?
createLevel = function (level, cb) {
if (this._level == _level0) {
loadMovieNum(_url, level);
this.onEnterFrame = function() {
var loadLevel = eval("_level"+level);
if (loadLevel.getBytesLoaded()>=loadLevel.getBytesTotal()) {
if(loadLevel != undefined) {
this.onEnterFrame = null;
this[cb]();
}
}
};
}
};
createLevel(2,"levelCB");
levelCB = function() {
_level2.myVariable = "Why does this work?";
trace(_level2.myVariable);
}
Flash
Finally got my drivers license today! Not that I drive all that much (though that’s likely because I didn’t have a license up to now). Now if I could only tear myself away from my computer long enough
General
Claus Wahlers has just announced that as of today DENG is free for non-commercial use. If that isn’t great news!
If you’re wondering what DENG is, think of a Flash component that parses and renders XHTML, XFORMS, SVG, XFRAMES and last but not least CSS versions 2 and 3 even more conform to the W3C standards than most browsers have it. Be sure to try give it a try, its available for download here!
Flash
If you’re working with Flash Remoting using AMF-PHP you might have encountered some problems in the latest release with doing multiple method calls. I’ve been browsing the mailinglist and came across a solution by Justin Watkins that fixes this problem.
You can download an updated version of “Executive.php” and use that to replace the old one (flashservices > app), you’ll also be required to do a little tweak to your “gateway.php” file:
$gateway->setBaseClassPath($_SERVER['DOCUMENT_ROOT'].“flashservices/services/”);
Those two changes should do the trick!
PHP
If you’ve been working with databinding in the Flash IDE I’m sure you’ve come across (or at least read about) the problems with cutting and pasting components or moving them inside a movieclip. Doing any of those things simply make all your bindings evaporate into thin air (cool huh!). True believers will tell you: “it’s not a bug, it’s a feature”, all I can add to that is that Flash MX 2004 is certainly a feature rich product!
In any case, for those reasons and a few other practical considerations I’ve taken to writing bindings using the runtime databinding API. There’s fairly little info posted about the subject and because I’ve been getting an increasing amount of questions about it I’ve made a few basic examples available for download.
When you first get started with the API it might look a bit scary but it’s in fact quite straight-forward. I’ll walk you through the necessary steps for a simple binding:
- Open up a new blank FLA
- Drag an instance of the DataBindingClasses into your library
(Window > Other Panels > Common Libraries > Classes)
- Drag two instances of the TextArea component on stage
(instancenames “fromText” and “toText”)
- Next you can start writing the actual ActionScript code:
import mx.data.binding.*
var from:Object = {component: fromText, property: “text”, event:”keyDown”};
var to:Object = {component: toText, property: “text”};
var myBinding:Binding = new Binding(from,to);
What the code above does is import the binding classes and define the “from” and “to” objects that contain information on what component properties to bind. When you look at the Flash MX 2004 documentation on this you’ll notice that they are using the EndPoint class but I’ve found regular objects work just as well.
In this case we’ll be using one-way binding between the text property of the two TextArea component and setting “KeyDown” as the event trigger. You can set an optional third and fourth argument when instantiating the Binding class that allows you to set a class formatter and whether or not it is a two-way binding. Check out “binding-formatter.fla” if you want to learn more about this!
Flash
I’m a bit late in blogging about this but Arul Kumaran has made an updated syntax file available for my favourite ActionScript editor: SciTE|Flash.
I recently started reworking some of my old code to ActionScript v2 classes and the syntax highlighting came in very handy indeed, thanks Arul!
Flash
Recent Comments