Thursday, June 21, 2007

URLRequest in AS3

ActionScript 3.0 is very different from its predecessors. Touted as a full-fledged programming language, it has some characteristics built into it that make it work more like other web programming languages and less like JavaScript, which is a good thing but will take some time getting used to.

For example, in AS 2.0, if I wanted to script a button to take me to a URL, I would simply select the button on the stage and write the following action in the Actions panel:

on (release) {
getURL("http://www.adobe.com", _blank);
}

That's no longer possible in AS 3.0. All scripts now must reside in the timeline or in an external file.

Also, that on (release) statement above makes some assumptions about what is going to be released and what object will be engaged when that event occurs. Event handlers are now more precise in AS 3.0 and it requires the aid of event listeners to trigger functions. The code is a lot longer than in the previous example, but the result is the same.

First, we start off by declaring a variable which will hold the URL we want to go to:

var link:URLRequest = new URLRequest("http://www.adobe.com");

You can still use buttons in Flash, but here I'm using a Movie Clip object as a button called 'button_mc.' I need to add an event listener to the object. The event listener has two arguments, the type of event and a function that will be triggered when that event occurs. In this case, I'm using a mouse event called click and creating a function called onClick.

button_mc.addEventListener(MouseEvent.CLICK, onClick);

The function is pretty simple, although the syntax is very different. Within the funtion we set an event parameter which corresponds to the event in the event listener. Then we use the navigateToURL function with a parameter called link, which looks back at our variable that holds the URL we want to navigate to.

function onClick(event:MouseEvent):void {
navigateToURL(link);
}

Since a Movie Clip object is not a button, it doesn't have mouse behaviors built into it. To enable mouse events on a Movie Clip, add the following:

button_mc.buttonMode = true;

You can see that the code is a lot longer than the AS 2 version, but it's more precise and consistent. Again, it will take a little getting use to, but it's worth it.

instructional design online training content development accessibility
section 508 interactivity learning activities
elearning podcasts usability CSS Flash XHTML
semantic markup

Friday, June 08, 2007

Kuler for Flash CS3

Kuler has been around for a while now and I really like it's implementation across the new creative suite. Now you can download a Kuler panel for Flash CS3. Select a palette and it draws it onto the stage for you.

http://pixelfumes.blogspot.com/2007/06/flash-cs3-kuler-panel-updates.html

Labels: ,