Posts in Category "ActionScript"

This Week’s Top Posts (10/17)

Here is a collection of blog posts from my coworkers on the Flex SDK, Flex Builder, AIR, and LCDS/BlazeDS teams:

And from our friends on the Flash Authoring, Flash Player, and Flash Platform Evangelism teams:

Various posts on the past Flash 10 Camp in San Francisco, as well as some videos from the past 360Flex conference in San Jose:

Today’s bonus link comes to us from Renaun Erickson, Flash/Flex Developer on “Pacifica” at Adobe:

This Week’s Top Posts (9/24)

Here is a collection of blog posts from my coworkers on the Flex SDK, Flex Builder, and LCDS/BlazeDS teams:

Various posts on the upcoming Adobe MAX (North America), as well as some videos from the past 360Flex conference in San Jose:

And from our good friends at the Adobe Flex Developer Center, Adobe Developer Connection, and the Adobe Labs site:

And from our friends on the Flash Player, Flash Authoring, and Flash Platform Evangelism teams:

Toggling specific compiler warnings in Flash CS3

The following question came up today, so I thought I’d post the answer here in case it helps a few other people out there.

In Flex, the following code generates a couple warnings:

<mx:Script>
<![CDATA[
private var i;

private function init() {
return true;
}
]]>
</mx:Script>

1008: variable ‘i’ has no type declaration.
1008: return value for function ‘init’ has no type declaration.

However, if you do the same thing in Flash CS3, you don’t get the same warnings:

var i;

function peter() {
return true;
}

If you want to see the same warnings in Flash, you can edit the EnabledWarnings.xml file in your /Configuration/ActionScript 3.0/ directory:

PC: C:\Program Files\Adobe\Adobe Flash CS3\en\Configuration\ActionScript 3.0\
Mac: /Applications/Adobe Flash CS3/Configuration/ActionScript 3.0/

Simply change the enabled attribute from false to true for the desired warnings (in this case, the warning id == 1008).

Hope that helps, and a big thanks to Nivesh for the explanation.

Catch Colin Moock’s free ActionScript 3.0 training course

I just got a note from my local Flex User Group (yay silvafug!), saying that Colin Moock is giving several free full-day training courses on ActionScript 3.0. For more information, see www.adobeas3tour.com/. It looks like there are already dates for San Francisco (Oct. 27), Los Angeles (Nov. 5), and New York (Nov. 12), and other cities (without dates) are Chicago, Tokyo, Amsterdam, London, Munich, Bangalore, and Sydney.

If you’re close to any of those cities, I recommend registering and checking it out. I’ve had the pleasure of seeing Colin speak on several occasions and he is outstanding. Plus, if you haven’t checked out his latest book, “Essential ActionScript 3.0″, I highly recommend it. I’ve been reading through it at home and it is full of great information, tips, and tricks. For more information on this great (and “ILLUSTRATED” — according to Amazon.com) book, check it out at Amazon.com.

Setting a Flash data grid’s background color based on a row’s data (ActionScript 3.0 edition)

Hot on the heels of the previous post… Here is another section of the third [and final] quick start on the Flash ActionScript 3.0 DataGrid component.

In this section we cover setting a row’s background color/skin based on the row’s data. And again I apologize for what will most certainly be hard to read formatting.

Continue reading…

Alternating background colors in a Flash data grid (ActionScript 3.0 edition)

Somebody was asking me today how to alternate background colors for the DataGrid component in Flash CS3 today (using the new ActionScript 3.0 components). Well, as luck has it, I wrote a section on it in an upcoming Flash Quick Start for the DataGrid component (my third and final installment on DataGrid).

The wording/code may change, but here’s the latest draft of the “Alternating background colors in a data grid” section. Oh, and don’t worry, the formatting will be *much* better once the Developer Center people clean it up.

Continue reading…

New content on the Flash Developer Center

After a “brief” absense from my blog, we’re back with a brief update…

Today we posted new items of interest (video, Quick Start tutorial, and article) on the Flash Developer Center:

Video interview: Flex Component Kit for Flash CS3
Flex SDK engineer Glenn Ruehle explains how the Flex Component Kit improves the workflow between Flex and Flash developers and designers.
(Note: There is also an excellent video by Steve Heintz, Sr. Product Manager for Adobe Flex Builder on the adjoining tab.)

Using the Button component in Flash CS3 Professional
Peter deHaan writes about some of the common ways to use the Button component in your Flash projects, including setting labels, resizing and positioning buttons, embedding fonts, and creating toggles.

Setting up a Flash project for local and network playback
Dan Carr shows you how to create Flash content for local and web delivery by understanding the various playback features and deployment options.

I also wanted to highlight an excellent article that I overlooked the other week:

Formatting text for localized Flash projects using CSS, HTML, and ActionScript by Dan Carr
Learn how to create Flash applications that display multiple languages using ActionScript and text formatting techniques.

I know this topic comes up quite a bit in forums, mailing lists, LiveDocs, etc. so it’s nice to have a bit of additional coverage. Thanks Dan!

Anyways, expect a few more posts around this dusty blog in the future. I missed you guys.

As always, you can find a lot more information and tutorials at the following URLs:
Developer Center
Flash Developer Center
Flash Developer Center Quick Starts

Using FlashVars with ActionScript 3.0

I was building a small app in Flash/ActionScript 3.0 over the weekend and needed to find out how to use FlashVars (Using FlashVars to pass variables to a SWF) to pass variables to my SWF file.

Previously, in ActionScript 2.0, you could pass variables along the query string or using FlashVars and the variables would be available in _level0, in ActionScript 3.0, it is a bit tricker:

<!-- using query string -->
<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000"
codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,0,0"
width="550"
height="400"
align="middle"
id="main">
<param name="allowScriptAccess" value="sameDomain" />
<param name="movie" value="main.swf?one=1&two=2" />
<param name="quality" value="high" />
<param name="bgcolor" value="#ffffff" />
<embed src="main.swf?one=1&two=2"
width="550"
height="400"
autostart="false"
quality="high"
bgcolor="#ffffff"
name="main"
align="middle"
allowScriptAccess="sameDomain"
type="application/x-shockwave-flash"
pluginspage="http://www.macromedia.com/go/getflashplayer" />
</object>

The previous code passes two variables (one and two) along the querystring (main.swf?one=1&two=2) and makes those variables available in your SWF file in the root’s loaderInfo object (or more accurately, within the loaderInfo’s parameters property).

Also, the same technique works if you pass the variables within a FlashVars parameter, as seen below:

&lt!-- using FlashVars -->
<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000"
codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,0,0"
width="550"
height="400"
align="middle"
id="main">
<param name="allowScriptAccess" value="sameDomain" />
<param name="movie" value="main.swf" />
<param name="quality" value="high" />
<param name="bgcolor" value="#ffffff" />
<param name="FlashVars" value="one=1&two=2" />
<embed src="main.swf"
width="550"
height="400"
autostart="false"
quality="high"
bgcolor="#ffffff"
FlashVars="one=1&two=2"
name="main"
align="middle"
allowScriptAccess="sameDomain"
type="application/x-shockwave-flash"
pluginspage="http://www.macromedia.com/go/getflashplayer" />
</object>

But enough of my rambling, how do you access these from within your FLA document? Read on!

// AS3
var tf:TextField = new TextField();
tf.autoSize = TextFieldAutoSize.LEFT;
tf.border = true;
addChild(tf);

tf.appendText("params:" + "\n");
try {
var keyStr:String;
var valueStr:String;
var paramObj:Object = LoaderInfo(this.root.loaderInfo).parameters;
for (keyStr in paramObj) {
valueStr = String(paramObj[keyStr]);
tf.appendText("\t" + keyStr + ":\t" + valueStr + "\n");
}
} catch (error:Error) {
tf.appendText(error.toString());
}

The previous code creates a new TextField instance on the Stage (named tf), uses a for..in loop to iterate over each of the passed parameters and displays the parameter’s names and values in the text field.

Nothing ground breaking or overly fascinating, but hopefully this helps somebody out there or saves them about 3 minutes of searching.

Using the Timer class in ActionScript 3.0

Another great new addition in ActionScript 3.0 is the Timer class (flash.utils.Timer), which essentially replaces the setInterval() and setTimeout() methods in ActionScript 2.0. For example, here’s an example of the setTimeout() method in ActionScript 2.0:

// AS2
var intID:Number = setTimeout(runOnce, 1000); // 1 second
function runOnce():Void {
trace("runOnce() called @ " + getTimer() + " ms");
}

In ActionScript 3.0, the same code could be rewritten as follows:

// AS3
var myTimer:Timer = new Timer(1000, 1); // 1 second
myTimer.addEventListener(TimerEvent.TIMER, runOnce);
myTimer.start();

function runOnce(event:TimerEvent):void {
trace("runOnce() called @ " + getTimer() + " ms");
}

Note that the Timer() constructor takes two parameters. The first parameter controls how frequently the TimerEvent.TIMER event gets dispatched (in milliseconds). The second parameter is the number of times that the TimerEvent.TIMER event will be dispatched before stopping. In this example, the timer will dispatch only once before quitting. If you set the second parameter to 0 (zero) or omitted it completely, the timer would run forever (or until you called the stop() method on the timer instance.

If you wanted the code to continuously run in ActionScript 2.0, you would use the setInterval() method instead of the setTimeout() method, as seen in the following example:

// AS2
var intID:Number = setInterval(runMany, 1000); // 1 second
function runMany():Void {
trace("runMany() called @ " + getTimer() + " ms");
}

The previous code snippet would continue to run until the interval was stopped by calling the clearInterval() method and passing in the interval id (which was saved in the variable intID). The same code could be rewritten in ActionScript 3.0 as follows:

// AS3
var myTimer:Timer = new Timer(1000); // 1 second
myTimer.addEventListener(TimerEvent.TIMER, runMany);
myTimer.start();

function runMany(event:TimerEvent):void {
trace("runMany() called @ " + getTimer() + " ms");
}

Playing back FLVs with ActionScript 3.0

OK, this isn’t a huge difference between ActionScript 2.0 and ActionScript 3.0, but it is good to know anyways…

In previous versions of ActionScript, in order to play back and FLV (without using a component) you’d need to create a Video object in the library, add it to the Stage, and give it an instance name, as seen in the following example:

// AS2
// requires: Video symbol on Stage with instance name of "myVideo".
var nc:NetConnection = new NetConnection();
nc.connect(null);
var ns:NetStream = new NetStream(nc);
myVideo.attachVideo(ns);
ns.play("http://www.helpexamples.com/flash/video/cuepoints.flv");

In ActionScript 3.0, you can now create a new Video object using the Video() constructor, and adding it to the display list using the addChild() method, as seen in the following example:

// AS3
var myVideo:Video = new Video();
addChild(myVideo);
var nc:NetConnection = new NetConnection();
nc.connect(null);
var ns:NetStream = new NetStream(nc);
myVideo.attachNetStream(ns);
ns.play("http://www.helpexamples.com/flash/video/cuepoints.flv");

Where it starts to get a bit more interesting, is when you want to work with video cue points and meta data. ActionScript 2.0 used the onCuePoint and onMetaData event handlers to process cue points and meta data, as shown in the following example:

// AS2
// requires: Video symbol on Stage with instance name of "myVideo".
var nc:NetConnection = new NetConnection();
nc.connect(null);
var ns:NetStream = new NetStream(nc);
ns.onCuePoint = function(infoObject:Object):Void {
trace("cuePoint");
}
ns.onMetaData = function (infoObject:Object):Void {
trace("metaData");
}
myVideo.attachVideo(ns);
ns.play("http://www.helpexamples.com/flash/video/cuepoints.flv");

In ActionScript 3.0, you have a few more options for handling the information. One of the simplest methods is to create a simple Object which processes the onCuePoint and onMetaData event handlers in ActionScript 3.0. You can see an example of this in the following code:

// AS3
var customClient:Object = new Object();
customClient.onCuePoint = cuePointHandler;
customClient.onMetaData = metaDataHandler;

var myVideo:Video = new Video();
addChild(myVideo);

var nc:NetConnection = new NetConnection();
nc.connect(null);
var ns:NetStream = new NetStream(nc);
ns.client = customClient;
myVideo.attachNetStream(ns);
ns.play("http://www.helpexamples.com/flash/video/cuepoints.flv");

function cuePointHandler(infoObject:Object):void {
trace("cuePoint");
}
function metaDataHandler(infoObject:Object):void {
trace("metaData");
}

This code begins by creating a new Object instance named customClient which defines listeners for the onCuePoint and onMetaData event handlers. The cuePointHandler and metaDataHandler variables point to user-defined functions which are defined later in the code. Later, the client property on the NetStream instance is set to the customClient object.

Another way of handling the cue points and meta data is to create a new class which you can use with the client property. The code is roughly similar to the previous example:

// AS3
var myVideo:Video = new Video();
addChild(myVideo);

var nc:NetConnection = new NetConnection();
nc.connect(null);
var ns:NetStream = new NetStream(nc);
ns.client = new CustomClient();
myVideo.attachNetStream(ns);
ns.play("http://www.helpexamples.com/flash/video/cuepoints.flv");

This time, instead of defining an object to handle the onCuePoint and onMetaData event handlers, the code is moved into an external file named “CustomClient”, which contains the following code:

package {
public class CustomClient {
public function onCuePoint(infoObject:Object):void {
trace("onCuePoint");
}
public function onMetaData(infoObject:Object):void {
trace("onMetaData");
}
}
}

On the other hand, if you wanted to ignore the cue point and meta data information from an FLV altogether, you could use either one of the following snippets:

// AS3
var myVideo:Video = new Video();
addChild(myVideo);

var nc:NetConnection = new NetConnection();
nc.connect(null);
var ns:NetStream = new NetStream(nc);
ns.client = new Object();
myVideo.attachNetStream(ns);
ns.play("http://www.helpexamples.com/flash/video/cuepoints.flv");

The previous example sets the client property to a new Object instance, which doesn’t have any event handlers for the onCuePoint and onMetaData callbacks. As an alternative, you could also set up an event listener for the AsyncErrorEvent.ASYNC_ERROR event which does nothing, as seen in the following code:

// AS3
var myVideo:Video = new Video();
addChild(myVideo);

var nc:NetConnection = new NetConnection();
nc.connect(null);
var ns:NetStream = new NetStream(nc);
ns.addEventListener(AsyncErrorEvent.ASYNC_ERROR, asyncErrorEventHandler);
myVideo.attachNetStream(ns);
ns.play("http://www.helpexamples.com/flash/video/cuepoints.flv");

function asyncErrorEventHandler(event:AsyncErrorEvent):void {
// ignore
}