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.
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.(
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
Class function com
Seems through experimentation that within classes it is impossible to access public class variables outside of a function, period. Public variables are accessible from document class but only from within its functions, not code within the class brackets.
Public variables get declared within the class brackets.
Public variables get declared within the class brackets.
Combo box tip
Just stumbled upon a combo box issue that might boggle ya. When adding listeners for keyboard KEY_DOWN type events you may run into trouble when opening a combo box. It may disable your key pressed listener.
Solution is simple. The Combo box draws focus away from the stage because it has its own keyboard commands for navigating the combo box. It gets left on even after your selection. Solution =
Solution is simple. The Combo box draws focus away from the stage because it has its own keyboard commands for navigating the combo box. It gets left on even after your selection. Solution =
someObject.setFocus()to draw focus away after combo box dropdown closed or a selection made.
Subscribe to:
Posts (Atom)
