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());
}
}
Tuesday, April 21, 2009
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);
}
Monday, February 16, 2009
getURL in as3
As we all know, there's no more getURL in as3. Below is the replacement of getURL,
navigateToURL(new URLRequest("http://google.com"), "_blank");
cheers!
navigateToURL(new URLRequest("http://google.com"), "_blank");
cheers!
How to set cookies in flash - as3 (Flash SharedObject)
the codes:
var sharedObj:SharedObject = SharedObject.getLocal("anyname");
sharedObj.data.object1 = "whateverYouWantToStore";
sharedObj.data.object2 = "whateverYouWantToStore";
sharedObj.flush();
sharedObj.close();
var sharedObj:SharedObject = SharedObject.getLocal("anyname");
sharedObj.data.object1 = "whateverYouWantToStore";
sharedObj.data.object2 = "whateverYouWantToStore";
sharedObj.flush();
sharedObj.close();
Subscribe to:
Posts (Atom)