ActionScript



Grumpy Old Flashers – The Rebel Alliance

LOL: Robert Penner wrote a funny “recollection” of The Rebel Alliance, the fight with the evil empire, during a time when Twitter was called Flashcoder.

Count Moockoo, Skypenner, I think we’re missing Hall Solo.

Here’s the quantum archive if you’re interested. Good old days…

Obiyang, heh.

posted on Sep 14, 2009 at 12:10 am in ActionScript | 2 Comments

Declaring variable type

During FITC this past weekend, I saw a presenter showing code such as:

var x, y:Number;

This innocent looking line may seem like declaring two variables x & y as the Number data type. However, what it actually does is declaring variable x with an undefined data type, and y as a Number.

To test, try this:

x = "";

Test movie, all is fine. No error message.

Now add this line:

y = "";

Test movie, and you’ll see the error message:

‘Type mismatch in assignment statement: found String where Number is required. y = “”;’

So remember to declare variables as intended, such as:

var x:Number;
var y:Number;

posted on Apr 24, 2006 at 5:32 pm in ActionScript, Events | 4 Comments

Flash Lite 2.0 Nokia S60 Template

Here is a Flash Lite 2.0 template for the Nokia S60 series. Yesterday‘s release doesn’t seem to include this template.

Place it in the “Configuration\Templates\Global Phones” directory.

For Windows, the default English location is:
C:\Program Files\Macromedia\Flash 8\en\Configuration\Templates\Global Phones

For Mac OS X, put the file here:
/Applications/Macromedia Flash 8/Configuration/Templates/Global Phones/

Download it here: http://quantumwave.com/pub/FL2_S60_Template.zip

When this is installed, you can choose it from Global Phones in the Start Page.

posted on Jan 4, 2006 at 1:14 pm in ActionScript, Devices, Flash, Flash Lite, Mobile & Devices | No Comments

ActionScript 3.0 & the Rebel Alliance

My journey along the prototype chain as a Rebel Alliance leader back in the Flash 5/MX days, using cool hacking techniques with my friend __proto__, made things like associating a movieclip with a class possible back then.

It’s been a long time since those hacks were needed – now with ActionScript 3.0, I have mixed feelings seeing my old friend being removed.

On one hand, I haven’t done anything with this friend for years; on the other hand, it’s been a great adventure exploring the deep dark secrets along the chain – an impossible task without this trusted friend.

Of course, these are all silly memories from an old guy who still enjoy adventures. But this time, it’s about other more exciting things, like: getting things done quicker without reinventing the wheel, using GUI for building applications (so almost anyone can do it, haha), and getting results fast. What has the world come to… 8-P

So, the Flex 2 product line is now in alpha, with Flex Framework 2, Flex Builder 2, Flash Player 8.5, ActionScript 3.0, among others new experiments that were just announced by Macromedia.

This journey is getting interesting again, even though we barely just started with Flash 8 and all its new cool features.

Oh, one more thing… Flex Builder 2 is available to everyone today for testing, see you later Sparkle8-)

posted on Oct 17, 2005 at 1:06 pm in ActionScript | 2 Comments

Create object from string of class name

Here’s a commonly asked question on how to instaniate an object from the name of a class at runtime:

To instantiate a class from a string of its name at runtime, the class needs to be referenced first. For example:

import MyClass; // optional
var tmp = MyClass;
delete tmp;

// construct the class name anyway you want
var dynamicClass:String = "MyClass";

// instantiate an object
var obj = new (eval(dynamicClass));

A related article I posted in 2002 (using ActionScript 1.0):

Invoking a dynamic class method: http://quantumwave.com/flash/dynamicMethod.html

posted on Jun 16, 2005 at 7:16 pm in ActionScript | 9 Comments

Attaching movieclip class without library symbol

Even though it is late Friday/early Saturday, I’ve got to write this one down:

Through an internal implementation of ActionScript 2.0′s compiler (which compiles code into ActionScript 1.0), Peter Hall discovered this little trick.

Here’s a shortened (and more obscured) example:

Actor.as:

class Actor extends MovieClip {
    static var id = (id="__Packages.Actor")+
        (Object.registerClass(id,Actor)?"":"");

    public function Actor() {
        trace("Action!");
    }
}

To test:

import Actor;
attachMovie(Actor.id, "_mc", 1);

This keeps the number of static variables to a minimum (one). Of course, this trick works only if the compiler uses the “__Packages.” prefix to the class path internally, and may not work in future versions of Flash. Nevertheless, it’s a very cool trick.

posted on Jan 31, 2004 at 12:47 pm in ActionScript | 9 Comments

Case sensitivity

One of the new features in Flash MX 2004 and the new Flash Player 7 is ActionScript case-sensitivity. Case-sensitivity is enforced only if the movie is published for Flash Player 7, and is not related to whether it is ActionScript 1.0 or 2.0.

For example, a Flash MX 2004 movie set to use ActionScript 2.0 and published to Flash Player 6, is not case-sensitive: swfoo and swFOO are the same.

On the other hand, a movie set to use ActionScript 1.0 and published to Flash Player 7 is case-sensitive: swfoo is different from swFOO.

So case-sensitivity is determined by the Flash player setting, not the version of ActionScript used. Thanks to Chafic Kazoun for the tip.

posted on Oct 9, 2003 at 5:13 am in ActionScript | 1 Comment

Import statement and code hints

Unlike the include directive, the import statement in ActionScript 2.0 requires a semi-colon at the end for code hints to work.

For example, without the semi-colon, code hints for the Accordion class is not displayed:

import mx.containers.Accordion
var ac:Accordion;
ac.

Code hints now work:

import mx.containers.Accordion;
var ac:Accordion;
ac.

Note that with or without the semi-colon, the class is still imported.

posted on Oct 9, 2003 at 4:37 am in ActionScript | 3 Comments

Ultrashock released a new series of Flash MX 2004 tutorials

Ultrashock has just released a whole series of tutorials on Flash MX 2004.

I was asked to write an article on Flash MX 2004 ActionScript 2.0.

Other topics include:

There are a few things I left out of the tutorial because of the little time I had:

Error class
try {} catch() {} throw {} finally {}
New event model
EventDispatcher vs. AsBroadcaster

posted on Oct 1, 2003 at 7:10 pm in ActionScript | 7 Comments

Auto Format your logic!

I just discovered a pretty serious bug with Auto-Format (MX 2004):

If you run the following code, you’ll get “true 2″:

function test() {
    if (true) {
        if (true) {
            trace("true 2");
        } else { // false 2
            trace("false 2");
        }
    } else { // false 1
        trace("false 1");
    }
}

test();

Now if you auto-format this code, and then run it, you’ll get:

true 2
false 2
false 1

Why? Because Auto-Format turns the code into:

function test() {
    if (true) {
        if (true) {
            trace("true 2");
        } else {
            // false 2
        }
        trace("false 2");
    } else {
        // false 1
    }
    trace("false 1");
}

test();

Note the last two trace() statements, they’re moved outside of the else blocks! This is because of the comments at the end of the two else statements (which are now inside the else blocks). So watch where you put your comments! You can try this by auto-formatting mx.events.EventDispatcher.as and see the same (make sure you don’t save it!)

By the way, I always put my curly braces like this, so I haven’t ran into this bug before, until I tried to auto-format EventDispatcher.as:

function test() {
    if (true) {
        // comments here
    } else {
        // and here
    }
}

The lesson of the day is: Don’t put your comments at the end of a statement and use auto-format, or you’ll run into logic changes like this!

posted on Sep 26, 2003 at 6:14 am in ActionScript | 3 Comments

Updated Class Browser with hidden classes

The “class browser” has been updated – it now includes hidden class files for data connectivity.

Unless you add these hidden files to the actual paths, you’ll see a little yellow triangle (see diagram) and won’t be able to double-click and see the class definitions. However, they’re still useful as a quick lookup of the class paths for entering into your code.

Note that the Include folder contains files that are part of Flash Remoting Components for Flash MX 2004.

For non-English installations, you may have to change the class paths in this .flp file. Open it up in a text editor, Find & Replace words like “/Program Files/” and “/en/” to your OS settings.

You can download the updated file here.

posted on Sep 23, 2003 at 6:28 pm in ActionScript, Flash Remoting, Web Services | 2 Comments

Generate project files automatically

Chris Kief of Rise Interactive released a Flash Project file generator that automatically creates something like the class browser. It requires ColdFusion 6+ to parse directories.

Get it from here.

posted on Sep 16, 2003 at 2:21 am in ActionScript, ColdFusion | 1 Comment

Cross domain policy file

These two important documents provide better understanding of the new Flash Player 7 security changes, and what to do about it:

Security Changes in Macromedia Flash Player 7

External data not accessible outside a Macromedia Flash movie’s domain

posted on Sep 13, 2003 at 6:43 am in ActionScript | No Comments

Inheritance in ActionScript 2.0

Back in the good old days of Flash 5 and MX, trying to do inheritance in ActionScript required some knowledge of what goes on behind the scene. Also, the infamous superclass invocation bug haunted developers for almost three years.

Now in ActionScript 2.0, with the new OOP-specific keywords, inheritance is much simpler:

class Parent {

}

class Child extends Parent {

}

That’s all. And the keyword “super()” in the Child class constructor is not even mandatory because the compiler inserts it for you!

As for the superclass invocation bug, it is now fix for Flash player 7!

posted on Sep 5, 2003 at 7:10 pm in ActionScript, OOP | 14 Comments

Code hints

In Flash MX 2004, some of the component code hints are not listed in AsCodeHints.xml or UIComponents.xml. As a result, what used to be a common thing to do in MX by using code hints such as _cb for ComboBox, does not work now.

Well, there are two solutions:

1) Add you own code hints information to the two files mentioned above.

2) Reference the component class in your code:

var sp:mx.containers.ScrollPane;

Now when you type sp. the list of ScrollPane methods and property is displayed!

Thanks go to Rebecca Sun of Macromedia for this tip.

posted on Sep 5, 2003 at 6:43 pm in ActionScript | 1 Comment

 
Copyright © 2003-2010 Dave Yang / Quantumwave Interactive Inc.