Tuesday, July 7, 2009

As3 tool

Here is some code to check the name and object class of buttons you click on in your project. The function is great for troubleshooting.
Notice that the up and down "volume" buttons return a target of [object VolUp] but they each have their own instance names "down and up". This is because I used the same symbol-"class" for both instances. Great for learning/finding errors.
Also notice you can click on the unnamed movieclips(level bars) and it displays their instance names.

The code snippet is the function that displays mouse click info. You will need to format the TextField to get it to display where and how you want it.( _text.width = 400;) for example.




Click anywhere on the player face above.
var _text:TextField = new TextField();

//testfunction
public function testIt(evt:MouseEvent):void
{
_text.text = "Event:\n" + evt + "\n\nClicked target = " +
evt.target + "\nClicked target name = " + evt.target.name;
addChild(_text);

trace("Ran button test:");
trace("clicked target = " + evt.target);
trace("clicked target name = " + evt.target.name)
}

No comments:

Post a Comment