In Actionscript 3, you write destroy() methods to clear up anything you’re not using:
public function destroy():void
{
removeChild(things-I-put-onto-the-stage);
things-I-put-onto-the-stage = null;
variables-I-created-in-this-class = null;
}
However, in Objective-C, you deallocate memory for anything you created when the class was instantiated:
- (void)dealloc {
[variables-I-created-in-this-class release];
[super dealloc];
}
Today I was thinking of a simple way to test for which direction the mouse is moving – is it moving left, or right?
A simple way to approach this would be to get the center of the stage, and see where the mouse is in relation to the center.
var stageCenter:Number = stage.stageWidth/2; // gets the center
If you pretend the center is 0 (zero), then left of the center would return a negative number, and right of the center would return a positive number.
var directionValue:Number = (mouseX - stageCenter)/stageCenter; // get a ratio of the mouse X position in relation to the center
checkDirection(directionValue);
You could then use a write a simple function that checks whether “directionValue” is a positive integer or a negative integer:
function checkDirection(value:Number):String
{
if (Math.abs(value) != value)
{
return "left";
}
else
{
return "right";
}
}
Gaia Framework: How to work with SWFAddress and SWF Assets from Nicole Chung on Vimeo.
Here are some code snippets I found useful when working with SWFAddress in the Gaia Framework, if anyone has more suggestions let me know!
To change the address:
Gaia.api.goto("index/nav/my-current-page/my-sub-page");
Gaia automatically listens for when the address changes, but if you are doing something special when the address changes (other than loading in a page) you can override the onDeeplink method:
overrride public function onDeeplink(e:GaiaSWFAddressEvent):void
{
trace(e.deeplink);// gets you the deeplink
// do your stuff here
}
When working with .swf assets, there’s no need to manually load the asset in (unless you want to), just include the following in your site.xml:
<asset id="yellow_mc" src="yellow.swf"/>
Then to make your .swf file visible, write:
IMovieClip(assets.yellow_mc).visible = true;
And to access items on the stage of your yellow_mc:
IMovieClip(assets.yellow_mc).content.instanceName = doSomething;
Using the Gaia Framework, it’s possible to use timeline-based transitions that are controlled by Actionscript using Frame Labels and Frame Scripts.
Even though there is an option to choose “Timeline” transitions, just use the “Actionscript” option instead
When you create your timeline transitions, add frame labels to your timeline at the start and beginning of each transition. Then, when the end of the timeline transition occurs, write a frame script that dispatches an event notifying the project that the end of the transition was reached
.
With flupie, you can create some great text animation events. However, it doesn’t work with actionscript StyleSheet objects, only TextFormat.
To use HTML text in with flupie, use the .htmlText property to combine bold, italic and regular styles in the same TextField:
format = new TextFormat("My-font-name");
message = new TextField();
message.defaultTextFormat = format;
myAnim = new TextAnim(message); myAnim.htmlText = " Some text here with bold text ";