Archive for the ‘ Flash ’ Category

Robotlegs / AS3 Signals Flickr Example

I’ve been spending some time with Robotlegs these days. I find it great to use and coming from PureMVC it was relatively easy to get the basics down.

What really helped me out a lot was Joel Hooks posts:

http://joelhooks.com/2011/03/12/an-introduction-to-robotlegs-as3-part-1-context-and-mediators/
http://joelhooks.com/2011/03/12/an-introduction-to-robotlegs-as3-part-2-models/
http://joelhooks.com/2011/03/12/an-introduction-to-robotlegs-as3-part-3-services/

And for working with Signals in RL:

http://joelhooks.com/2010/02/14/robotlegs-as3-signals-and-the-signalcommandmap-example/

I’ve created a simple app to help me understand the communication between mediators, controllers, and models/services. The app searches for photos on Flickr and presents them in a list, clicking on an item in the list loads the photo. I first tried this with using Events, then moved on to using Signals. You can download the source for this on gitub.

Let me know what you think!

The Undocumented “addFrameScript” Method

There’s a useful function inside the MoveClip class (AS3) that will add script inside a Movieclip on a specific frame without actually having to add it manually to the timeline. This is great if, say you have someone working purely on animation and then someone else working on the interface to hold/play/control the animation. A lot of times this person will need to know when then animation has completed and will therefore need to add script inside the MovieClip animation. The addFrameScript can do this for you without altering the animation and re-exporting, etc.

The function takes two parameters: frame number to place the script (0 based) and the function name to call.

public function addFrameScript (frame:uint, notify:Function):void;

Example:

1
2
3
4
5
6
7
8
 
// animation is the name of the movieclip.. 
animation.addFrameScript (77, onAnimationEnd);      
 
// function called when playhead reaches 76.. 
private function onAnimationEnd ():void { 
	trace ("onAnimationEnd.."); 
}

StopWatch Class

I worked on a couple projects a while back that required a stopwatch (or timer) to keep track of time in a game, so I made this StopWatch class. Found it very helpful so I wanna share it. Besides the basic functions of starting, stopping, and resetting, you can also pass in a TextFormat object to change the formatting of the text, get the time in milliseconds (it’s what I used to store in the database), and parse the milliseconds back into something more readable..

Here’s how to use it:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
import ca.ryac.StopWatch;        
 
// creates a StopWatch obj and sets the formatting to the txtFormat obj.. 
// last parameter will set embeddedFonts to either true or false (default is false).. 
var sw:StopWatch = new StopWatch (txtFormat, true);        
 
// pretty self-explanatory.. 
sw.start (); 
sw.stop (); 
sw.reset ();        
 
// set or change the formatting and sets embeddedFonts to true.. 
sw.setTextFormat (txtFormat2, true);        
 
// output the time in milliseconds 
trace (sw.time);        
 
StopWatch.parseTime (87292); // returns 01:27:29

Download StopWatch.as