// Importing classes from fl package must be done explicitly
import fl.transitions.Tween;
import fl.transitions.easing.*;
// Declare variables for the tween movement. These could just as easily be local below.
var moveBackX:Tween;
var moveBackY:Tween;
var moveRound:Tween;
moveBackX = new Tween(dragger, "x", Strong.easeOut, dragger.x, holder.x, 0.5, true);
moveBackY = new Tween(dragger, "y", Strong.easeOut, dragger.y, holder.y, 0.5, true);
moveRound = new Tween(dragger, "rotation", Strong.easeIn, 0, 180, 0.5, true);
Thursday, April 23, 2009
Tuesday, April 21, 2009
AS3 - Set frameRate at runtime
Framerate can now be set at runtime on per-VM instance basis (ie. it will affect all timelines, including loaded SWFs).
stage.frameRate = fps; //0.01 - 1000
stage.frameRate = fps; //0.01 - 1000
AS3 - Use getStackTrace for debugging
You can use the getStackTrace method of an Error instance for general debugging purposes. This will output the execution stack like so:
Test condition @Error
at Untitled_fla::MainTimeline/testingSomething()
at Untitled_fla::MainTimeline/MyThing_fla::frame1()
code:
function testingSomething():void {
if (testCondition) {
//include a stack trace with our debug trace:
trace("Test condition @" + (new Error()).getStackTrace());
}
}
Test condition @Error
at Untitled_fla::MainTimeline/testingSomething()
at Untitled_fla::MainTimeline/MyThing_fla::frame1()
code:
function testingSomething():void {
if (testCondition) {
//include a stack trace with our debug trace:
trace("Test condition @" + (new Error()).getStackTrace());
}
}
Depths in AS3
In AS3 it is easiest to work with depths in relative terms: Which element should be on top of the other?
Most people think this way anyway, the language reflects that now.
// get the depth of an existing sprite:
var depth:uint = getChildIndex(topMC);
//place mySprite under topMC:
addChildAt(mySprite, depth);
// or just:
addChildAt(mySprite, getChildIndex(topMC));
// directly set depth index:
setChildIndex(myMC, depth);
Most people think this way anyway, the language reflects that now.
// get the depth of an existing sprite:
var depth:uint = getChildIndex(topMC);
//place mySprite under topMC:
addChildAt(mySprite, depth);
// or just:
addChildAt(mySprite, getChildIndex(topMC));
// directly set depth index:
setChildIndex(myMC, depth);
AS3 New TextField methods
There are a number of new methods on text fields that allow you to work with text in more interactive manner, including methods to convert character indexes to pixel positions, find lengths of lines and paragraphs, get line metrics (ascent, descent, leading, etc), and more.
//px position of chars & vice versa:
myTF.getCharBoundaries(index)
myTF.getCharIndexAtPoint(x,y)
//and a TON more:
myTF.getParagraphLength(index)
myTF.getLineIndexOfChar(index)
//px position of chars & vice versa:
myTF.getCharBoundaries(index)
myTF.getCharIndexAtPoint(x,y)
//and a TON more:
myTF.getParagraphLength(index)
myTF.getLineIndexOfChar(index)
Flash - Double click event in AS3
AS3 adds a DOUBLE_CLICK event that uses the system setting for double click speed. Note that you will still get a click event before the double click event.
myButton.addEventListener(MouseEvent.DOUBLE_CLICK, handleDoubleClick);
myButton.doubleClickEnabled = true;
myButton.addEventListener(MouseEvent.DOUBLE_CLICK, handleDoubleClick);
myButton.doubleClickEnabled = true;
Flash - Create text link in AS3
HTML text fields no longer support "asfunction:" links. Instead they support "event:" links, which will generate a TextEvent.
myTextField.htmlText = "<a href="event:text">test</a>";
myTextField.addEventListener(TextEvent.LINK, handleLink);
function handleLink(evt:TextEvent):void {
trace(evt.text);
}
myTextField.htmlText = "<a href="event:text">test</a>";
myTextField.addEventListener(TextEvent.LINK, handleLink);
function handleLink(evt:TextEvent):void {
trace(evt.text);
}
Subscribe to:
Posts (Atom)