_secondsRound = Math.round(_theSound.length / 10) * 10 / 1000;
Tuesday, July 7, 2009
Math.round decimal places
Here is some rounding help. This converts miliseconds to seconds with two decimal places. Note the "/10) * 10" part, that rounds it to 2 decimal places, "/100) * 100" would round it to one decimal place.
Set Focus
Just sharing some info about focus in As3.
Opon experimenting with text input boxes I discovered that setFocus(), when uses on a hidden text input box was a great way to hide a cursor after ENTER event.
Opon experimenting with text input boxes I discovered that setFocus(), when uses on a hidden text input box was a great way to hide a cursor after ENTER event.
drawFocus() also comes in handy to bring a field back into perspective.
Top of display list
Example of setChildIndex to bring your display object to the top.
import flash.display.Sprite;
import flash.events.MouseEvent;
var container:Sprite = new Sprite();
addChild(container);
var circle1:Sprite = new Sprite();
circle1.graphics.beginFill(0xFF0000);
circle1.graphics.drawCircle(40, 40, 40);
circle1.addEventListener(MouseEvent.CLICK, clicked);
var circle2:Sprite = new Sprite();
circle2.graphics.beginFill(0x00FF00);
circle2.graphics.drawCircle(100, 40, 40);
circle2.addEventListener(MouseEvent.CLICK, clicked);
var circle3:Sprite = new Sprite();
circle3.graphics.beginFill(0x0000FF);
circle3.graphics.drawCircle(70, 80, 40);
circle3.addEventListener(MouseEvent.CLICK, clicked);
container.addChild(circle1);
container.addChild(circle2);
container.addChild(circle3);
addChild(container);
function clicked(event:MouseEvent):void {
var circle:Sprite = Sprite(event.target);
var topPosition:uint = container.numChildren - 1;
container.setChildIndex(circle, topPosition);
}
Variable behaviors
While working with public variables within a custom class i had the following observations:
Created a new TextField in the constructor function and change the variable.text in another function by mouseclick. The result was that the textfield was updated at each mouse click.
Conversely if you create the TextField within the mouse click event handler function the textfield keeps placing text on top of text each time the mouse is clicked.
Conclusion, creating TextField by a function variable stacks instance upon instance instead of just changing the single "public variable" each time the mouse is clicked. Might be handy for adding a bunch of graphics on top of one another in the display list.
Created a new TextField in the constructor function and change the variable.text in another function by mouseclick. The result was that the textfield was updated at each mouse click.
Conversely if you create the TextField within the mouse click event handler function the textfield keeps placing text on top of text each time the mouse is clicked.
Conclusion, creating TextField by a function variable stacks instance upon instance instead of just changing the single "public variable" each time the mouse is clicked. Might be handy for adding a bunch of graphics on top of one another in the display list.
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.(
Click anywhere on the player face above.
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)
}
Access display object name
Function of parent MC
Subscribe to:
Posts (Atom)
