Training Code Not working - actionscript-3

So I am going through the book "ActionScript 3.0 Animation ~ Making Things Move" by Keith Peters, and one of the examples is teaching Parent Boxs... I have written this code out, and upon execution, it runs, but provides no Errors, nothing happens, none of the Sprites are drawn, its a blank canvas..? Using Flash Pro CS 6, 12.0.2.529. I haven't had issues with any other examples as of yet, and the .as "ParentBox" runs fine, when I try to run ParentBox2 is when I am encountering this issue.... Thoughts? (sorry, pretty new to OOP, trying to learn as much as I can, and this website in particular has ben AMAZING so far for the vast wealth of knowledge....
ParentBox.as
package {
import flash.display.Sprite;
public class ParentBox extends Sprite {
public function ParentBox()
{
init();
}
private function init():void{
graphics.lineStyle(1, 0);
graphics.drawRect(-50, -50, 100, 100);
}
}}
ParentBox2.as Code....
package {
import flash.display.Sprite;
import flash.events.MouseEvent;
public class ParentBox2 extends Sprite {
private var parent1:ParentBox;
private var parent2:ParentBox;
private var ball:Sprite;
public function Reparenting2 (){
init();
}
private function init():void{
parent1 = new ParentBox();
addChild(parent1);
parent1.x = 60;
parent1.y = 60;
parent2 = new ParentBox();
addChild(parent2);
parent2.x = 170;
parent2.y = 60;
ball = new Sprite();
parent1.addChild(ball);
ball.graphics.beginFill(0xff0000);
ball.graphics.drawCircle(0, 0, 40);
ball.graphics.endFill();
ball.addEventListener(MouseEvent.CLICK, onBallClick);
}
public function onBallClick(event:MouseEvent):void{
parent2.addChild(ball);
}
}}

You have already found the answer, but for any one else having the same problem,
In ActionScript3 the constructor function should have the same name as the class name.
package {
import flash.display.Sprite;
import flash.events.MouseEvent;
public class ParentBox2 extends Sprite {
private var parent1:ParentBox;
private var parent2:ParentBox;
private var ball:Sprite;
public function ParentBox2 (){ //the constructor function's name should be the same as that of the class.
init();
}
...

The
public class ParentBox2 extends Sprite {
needed to be renamed to
public class Reparenting2 extends Sprite {
for the function... Like I said, I'm still learning, especially the naming stuffs, thanks everyone!

Related

AS3 - Call a method between classes

I'm almost entirely new to OOP, and I just don't understand how to call a method in one class from another. I'm trying to call a method in the Main.as from a custom class, but it always comes up as the "Call to possibly undefined method" error, and I don't know a way around it.
Main.as code:
package {
import flash.display.MovieClip;
public class Main extends MovieClip {
public var titleScreen:TitleScreen = new TitleScreen();
public var feedMeShibe:FeedMeShibe = new FeedMeShibe; //These are exported
public var milkbone:MilkboneItem = new MilkboneItem; //actionscript symbols
public var openMouthArea:OpenMouthArea = new OpenMouthArea; //in the library
public function Main() {
titleScreen.x = 350;
titleScreen.y = 250;
addChild(titleScreen);
}
public function addShibe(shibeX:Number, shibeY:Number, shibeSize:Number):void {
feedMeShibe.x = shibeX;
feedMeShibe.y = shibeY;
feedMeShibe.width = feedMeShibe.width*shibeSize;
feedMeShibe.height = feedMeShibe.height*shibeSize;
addChild(feedMeShibe);
}
public function addMilkbone(milkboneX:Number, milkboneY:Number, milkboneSize:Number):void {
milkbone.x = milkboneX;
milkbone.y = milkboneY;
milkbone.width = milkbone.width*milkboneSize;
milkbone.height = milkbone.height*milkboneSize;
addChild(milkbone);
}
public function addOpenMouthArea(OMAX:Number, OMAY:Number, OMAW:Number, OMAH:Number):void {
openMouthArea.x = OMAX;
openMouthArea.y = OMAY;
openMouthArea.width = OMAW;
openMouthArea.height = OMAH;
addChild(openMouthArea);
}
}
}
TitleScreen.as code:
package {
import flash.display.MovieClip;
import flash.events.Event;
import fl.transitions.Tween;
import fl.transitions.easing.*;
import fl.transitions.TweenEvent;
public class TitleScreen extends MovieClip {
public function TitleScreen() {
createListeners();
}
private function createListeners():void {
this.addEventListener(Event.ENTER_FRAME, stopFrame);
}
public function stopFrame(e:Event):void {
if (this.currentFrame == 510){
this.removeEventListener(Event.ENTER_FRAME, stopFrame);
this.stop();
addShibe(100, 100, 0.5); //How do I
addMilkbone(50, 50, 0.6); //access the Main class
addOpenMouthArea(200, 200, 1, 1); //with these?
}
}
}
}
I don't normally ask questions online, but I'm at the end of my rope here. I'm completely stumped, and browsing tutorials and previous questions online is only further confusing me. Any help would be greatly appreciated.
The most simple way to do that is to have one class to reference another class. Let's say you have a switch and a bulb. The switch can tell the bulb to turn lights on and off.
Here's a minimalistic example of how it could look like:
var bulbInstance:Bulb = new Bulb();
var switchInstance:LightSwitch = new LightSwitch();
switchInstance.bulbReference = bulbInstance;
now you have a bulb referenced in your switch class. Inside from it you can call public methods and access public variables of the Bulb class.
Don't forget to make a public variable bulbReference in your LightSwitch class.
There are many ways to form dependencies between elements of your code to break strong dependencies and make your code: scalable, reusable and maintainable. To learn about it look for Design Patterns. There is a great book written about this topic: http://shop.oreilly.com/product/9780596528461.do
But there's a lot of material on the topic free on the Internet.
If I'm not mistaken all you have to do is
Main.addShibe(100, 100, 0.5); //How do I
Main.addMilkbone(50, 50, 0.6); //access the Main class
Main.addOpenMouthArea(200, 200, 1, 1); //with these?

AS3 I don't understand the different treatment of an extended movieclip class vs extended simplebutton class

I recently discovered the custom classes in actionscript 3. I started using them in my latest project but I find it hard to bend my brain around how it all works.
I created two different classes to test.
One is an extended movieclip called "Persoon" and the other is an extended simplebutton called "SpeakerBtn".
package {
import flash.display.Sprite;
public class Persoon extends Sprite {
public function Persoon(xPos:Number, yPos:Number, naam:String) {
var persoon:Sprite = new Sprite;
persoon.graphics.beginFill(0x000000,1);
persoon.graphics.drawCircle(xPos, yPos, 2);
persoon.graphics.endFill();
this.addChild(persoon);
trace ("hij heet " + naam);
}
}
}
package {
import flash.display.SimpleButton;
import flash.events.MouseEvent;
import flash.media.Sound;
import flash.media.SoundChannel;
public class SpeakerBtn extends SimpleButton {
public var snd:Sound;
public var cnl:SoundChannel = new SoundChannel();
public function SpeakerBtn(xp:Number,yp:Number,naam:String) {
var speaker:SimpleButton = new SimpleButton();
speaker.name = naam;
speaker.x = xp;
speaker.y = yp;
speaker.addEventListener(MouseEvent.CLICK, playSnd);
//this.addChild(speaker);
}
public function playSnd (event:MouseEvent) : void {
trace ("ping");
}
}
}
Then I have my main:
package {
import flash.display.MovieClip;
import SpeakerBtn;
import flash.display.SimpleButton;
import Persoon;
public class Main extends MovieClip {
var sp:SpeakerBtn;
var ps:Persoon;
public function Main() {
sp = new SpeakerBtn(50,50,"donna");
addChild(sp);
ps = new Persoon(300,300,"wilf");
addChild(ps);
}
}
}
Persoon wilf works like I expected, displays fine and traces correctly.
SpeakerBtn donna does not display and does not trace correctly. I commented out the addChild in the SpeakerBtn package because if I turn it on, I get the error 1061: Call to a possibly undefined method addChild through a reference with static type SpeakerBtn
I noticed that when I define the x and the y and addChild in Main for the speakerBtn it does work. But I don't want to have to define all that in Main, I want my SpeakerBtn to do all that.
I checked this question but it does not provide me with an answer. Can someone explain to me what is happening, or alternatively link me to a comprehensible tutorial (one not too heavy on techspeak, more like an explain-it-to-me-like-I'm-5-years-old)? Thanks!
Update
I forgot to add a button with the class SpeakerBtn to my library, so there was nothing to display. Fixed that now, and with this code the button does appear on the stage, only the x and y values are not registered and it appears on 0,0. Also, the event playSnd does not trigger the trace and I assume is not working.
Solution
With help of Cherniv's information I came to the following solution for my SpeakerBtn.
Main does this:
package {
import flash.display.MovieClip;
import SpeakerBtn;
import flash.display.SimpleButton;
public class Main extends MovieClip {
var sp:SpeakerBtn;
public function Main() {
sp = new SpeakerBtn("donna", 300, 50);
addChild(sp);
}
}
}
And SpeakerBtn does this:
package {
import flash.display.SimpleButton;
import flash.events.MouseEvent;
import flash.media.Sound;
import flash.media.SoundChannel;
import flash.display.Sprite;
import flash.events.Event;
import flash.net.URLRequest;
public class SpeakerBtn extends SimpleButton {
private var snd:Sound;
private var cnl:SoundChannel = new SoundChannel();
private var _naam:String;
private var _x:Number;
private var _y:Number;
public function SpeakerBtn(naam:String, xp:Number, yp:Number) {
_naam = naam;
_x = xp;
_y = yp;
addEventListener(Event.ADDED_TO_STAGE, addBtn);
}
private function addBtn (event:Event) : void {
this.x = _x;
this.y = _y;
this.name = _naam;
snd = new Sound(new URLRequest("mp3/" + _naam + ".mp3"));
addEventListener(MouseEvent.CLICK, playSnd);
}
private function playSnd (event:MouseEvent) : void {
cnl = snd.play();
}
}
}
So what I did was add an EventListener for when the button was added to the stage and then set all the variables like x-position, y-position and name.
That's because of inheritance. Your SpeakerBtn doesn't inherits the addChild method from his ancestors , because as we can see in SimpleButton's documentation it is inheritor of DisplayObject and not of DisplayObjectContainer , which do have a addChild method and passes it to all his inheritors including MovieClip and Persoon.

tweenlite is not declared

package com.powerflasher.SampleApp {
import flash.events.MouseEvent;
import flash.display.Sprite;
public class test1 extends Sprite {
public function test1()
{
NewCircle1();
NewButton1();
Magic();
}
private function NewButton1():void
{
var NewButton:Sprite = new Sprite();
NewButton.graphics.beginFill(0x0000ff,1);
NewButton.graphics.drawRect(100, 100, 50, 50);
NewButton.graphics.endFill();
addChild(NewButton);
NewButton.addEventListener(MouseEvent.CLICK, Magic);
}
private function NewCircle1():void
{
var NewCircle:Sprite = new Sprite();
NewCircle.graphics.beginFill(0x000000,1);
NewCircle.graphics.drawCircle(400, 500, 50);
NewCircle.graphics.endFill();
addChild(NewCircle);
}
private function Magic():void {
Tweenlite.to(NewCircle1(), 2+Math.random()*6, {x:Math.random()*20, y:Math.random()*25, scaleX:Math.random()*3, ScaleY:Math.random()*5});
}}}
All that i'm trying to do is to draw square, draw circle, and on mouse click on square to move circle to random location
getting error "Variable 'Tweenlite' is not declared", have no idea..
There are several issues with your code, but in regards to your initial question, you need to import Tweenlite if you want to use it in your class.
import com.greensock.Tweenlite;
But you also have other problems with your code that will likely cause a problem next. You are using local variables to store your sprite instances. That means the variable name will not persist beyond the completion of those methods.
NewButton and NewCircle need to be made class properties so that they are available to the all the methods in the class.
Here's an example :
package com.powerflasher.SampleApp {
import flash.events.MouseEvent;
import flash.display.Sprite;
import com.greensock.Tweenlite; // import Tweenlite
public class test1 extends Sprite {
// declare your class properties
public var NewButton:Sprite;
public var NewCircle:Sprite;
public function test1()
{
NewCircle1();
NewButton1();
Magic();
}
private function NewButton1():void
{
NewButton = new Sprite();
NewButton.graphics.beginFill(0x0000ff,1);
NewButton.graphics.drawRect(100, 100, 50, 50);
NewButton.graphics.endFill();
addChild(NewButton);
NewButton.addEventListener(MouseEvent.CLICK, Magic);
}
private function NewCircle1():void
{
NewCircle = new Sprite();
NewCircle.graphics.beginFill(0x000000,1);
NewCircle.graphics.drawCircle(400, 500, 50);
NewCircle.graphics.endFill();
addChild(NewCircle);
}
private function Magic():void
{
Tweenlite.to(NewCircle, 2+Math.random()*6, {x:Math.random()*20, y:Math.random()*25, scaleX:Math.random()*3, ScaleY:Math.random()*5});
}
}
}
In the TweenLite function, you have - NewCircle1(). But that function doesn't return object, so error is coming, because you are trying to tween - nothing.

Adding eventlisteners in main document class for external classes

I have a small project I'm trying to help learn as3. It is a variation from the book Foundation Game Design with Actionscript 3.0. I am using an fla only to have a document class. All art is loaded within the as files. In the book, he just put all the code in the document class, I followed along and it worked as expected. I am trying to break out the code into separate classes to get a handle on OOP. One class makes a background - Background.as, one makes a character - Character.as, and one makes a button, which I instantiate 6 times for 6 different buttons - GameButton.as. And of course there is GameWorld.as which is the document class. Everything loads and shows up as expected. However when I try and add an eventListener for the buttons, I don't get any response. I have tried putting the eventListener in the GameButton.as and also tried it in the GameWorld.as neither of which has worked. Also I pass a reference to the stage when instantiating the various classes, because when I tried to addChild in the GameWorld.as, nothing would show up. I searched the site and found something similar, but it didn't seem to help. Thank you in advance for any advice you my have. Here is the code:
GameWorld.as
package
{
import flash.net.URLRequest;
import flash.display.Loader;
import flash.display.Sprite;
import flash.display.DisplayObject
import flash.events.MouseEvent;
import GameButton;
import Character;
import Background;
[SWR(width = "550", height = "400", backgroundColor = "#FFFFFF", frameRate = "60")]
public class GameWorld extends Sprite
{
//public variables
//Background
public var gameBackground:Background;
//Character
public var catCharacter:Character;
//Buttons
public var upButton:GameButton;
public var downButton:GameButton;
public var growButton:GameButton;
public var shrinkButton:GameButton;
public var vanishButton:GameButton;
public var spinButton:GameButton;
public function GameWorld ()
{
//Add the background to the stage
gameBackground = new Background("../images/background.png", stage);
//Add the character(s) to the stage
catCharacter = new Character("../images/character.png", stage);
//Set initial character position
catCharacter.CharacterPos(225, 150);
//Add the buttons to the stage
upButton = new GameButton("../images/up.png", stage, 25, 25);
downButton = new GameButton("../images/down.png", stage, 25, 85);
growButton = new GameButton("../images/grow.png", stage, 25, 145);
shrinkButton = new GameButton("../images/shrink.png", stage, 425, 25);
vanishButton = new GameButton("../images/vanish.png", stage, 425, 85);
spinButton = new GameButton("../images/spin.png", stage, 425, 145);
//Button event handlers
upButton.addEventListener(MouseEvent.CLICK, upButtonHandler);
}
public function upButtonHandler(event:MouseEvent)
{
trace("You clicked the up button!");
catCharacter.CharacterMove(15);
}
}
}
GameButton.as
package
{
import flash.net.URLRequest;
import flash.display.Loader;
import flash.display.Sprite;
import flash.display.Stage;
import flash.events.MouseEvent;
public class GameButton extends Sprite
{
//public variables
public var stageRef:Stage;
public var urlRequest:URLRequest;
public var gameButtonLoader:Loader;
public var gameButtonSprite:Sprite;
//Constructor
public function GameButton (urlRequest:String, stageRef:Stage, xPos:Number, yPos:Number)
{
this.stageRef = stageRef
this.urlRequest = new URLRequest();
gameButtonLoader = new Loader();
gameButtonSprite = new Sprite();
this.urlRequest.url = urlRequest;
gameButtonLoader.load(this.urlRequest);
gameButtonSprite.addChild(gameButtonLoader);
this.stageRef.addChild(gameButtonSprite);
gameButtonSprite.buttonMode = true;
gameButtonSprite.x = xPos;
gameButtonSprite.y = yPos;
}
}
}
Character.as
package
{
import flash.net.URLRequest;
import flash.display.Loader;
import flash.display.Sprite;
import flash.display.Stage;
public class Character
{
//private variables
private var stageRef:Stage;
private var urlRequest:URLRequest;
private var characterLoader:Loader;
private var characterSprite:Sprite;
//public variables
public var character_x_pos:Number;
public var character_y_pos:Number;
//Constructor
public function Character (urlRequest:String, stageRef:Stage)
{
this.stageRef = stageRef;
this.urlRequest = new URLRequest();
characterLoader = new Loader();
characterSprite = new Sprite();
this.urlRequest.url = urlRequest;
characterLoader.load (this.urlRequest);
characterSprite.addChild (characterLoader);
this.stageRef.addChild (characterSprite);
characterSprite.mouseEnabled = false;
}
//Set the position of the character
public function CharacterPos(xPos:Number, yPos:Number):void
{
characterSprite.x = xPos;
characterSprite.y = yPos;
}
//Move the position of the character
public function CharacterMove( yPos:Number):void
{
characterSprite.y -= yPos;
}
}
}
Background.as
package
{
import flash.net.URLRequest;
import flash.display.Loader;
import flash.display.Sprite;
import flash.display.Stage;
public class Background
{
//Private variables
private var stageRef:Stage;
private var urlRequest:URLRequest;
private var backgroundLoader:Loader;
private var backgroundSprite:Sprite;
//Constructor
public function Background (urlRequest:String, stageRef:Stage)
{
this.stageRef = stageRef;
this.urlRequest = new URLRequest();
backgroundLoader = new Loader();
backgroundSprite = new Sprite();
this.urlRequest.url = urlRequest;
backgroundLoader.load (this.urlRequest);
backgroundSprite.addChild (backgroundLoader);
this.stageRef.addChild (backgroundSprite);
backgroundSprite.mouseEnabled = false;
}
}
}
All art is loaded within the as files.
This is not an approach I recommend. There's a reason God gave us the Flash IDE--and it's not to write code! Any time you're spending on layout and viduals in code is just wasted, unless you have an actual requirement to change the visuals at runtime. The fact that your paths are all hard-coded suggests that you don't have that requirement.
So let's step back and imagine that you have a Symbol that contains 6 Symbols that you've created as just Flash buttons (when you select Button as the Symbol type). These will be SimpleButtons, but in the Class below we're just going to type them as DisplayObject. The Class doesn't care what they are, but using Simplebutton gives them up, over, down and hit states that require no code.
Note that the below assumes you have "automatically declare stage instances" off, which is IMO the best way to do things.
package view {
public class NavBar extends Sprite {
//because you put these on stage in the Symbol, they will be available in the constructor
public var upButton:DisplayObject;
public var downButton:DisplayObject;
public var growButton:DisplayObject;
public var shrinkButton:DisplayObject;
public var rotateButton:DisplayObject;
public var vanishButton:DisplayObject;
//makes it easier to do the same setup on all buttons
protected var allButtons:Vector.<DisplayObject> = <DisplayObject>([upButton, downButton, growButton, shrinkButton, rotateButton, vanishButton]);
public function NavBar() {
super();
for each (var btn:DisplayObject in allButtons) {
btn.buttonMode = true;
btn.mouseChildren = false;
btn.addEventListener(MouseEvent.CLICK, onButtonClick);
}
}
protected function onButtonClick(e:MouseEvent):void {
switch (e.target) {
case upButton:
dispatchEvent(new CharacterEvent(CharacterEvent.UP));
break;
case downButton:
dispatchEvent(new CharacterEvent(CharacterEvent.DOWN));
break;
case growButton:
dispatchEvent(new CharacterEvent(CharacterEvent.GROW));
break;
case shrinkButton:
dispatchEvent(new CharacterEvent(CharacterEvent.SHRINK));
break;
case rotateButton:
dispatchEvent(new CharacterEvent(CharacterEvent.ROTATE));
break;
case vanishButton:
dispatchEvent(new CharacterEvent(CharacterEvent.VANISH));
break;
default:
break;
}
}
}
}
Note that there's zero layout code. This code is dependent on a custom Event Class. I'm going to write that Event Class so that it always bubbles. That way, it can be dispatched anywhere on the display list and received at the top level:
package control {
class CharacterEvent extends Event {
public static var UP:String = 'characterUp';
public static var DOWN:String = 'characterDown';
public static var GROW:String = 'characterGrow';
public static var SHRINK:String = 'characterShrink';
public static var ROTATE:String = 'characterRotate';
public static var VANISH:String = 'characterVanish';
public function CharacterEvent(type:String) {
super(type, true, true);//always bubbles
}
public function clone():Event {
return new CharacterEvent(type);
}
}
}
Now, if you want to manually handle instantiation of the Symbol that has view.NavBar as its base class, it will look like this:
package {
public var navBar:NavBar;
class GameWorld {
public function GameWorld() {
try {
var navClass:Class = getDefinitionByName('NavBarSymbol') as Class;
} catch (e:Error) {
trace('You need to have a Library symbol called NavBarSymbol');
}
if (navClass) {
navBar = new navClass() as NavBar;
//unnecessary layout code here
//Note that this is NOT the responsibility of the child Class!
addChild(navBar);
}
//instantiate character
...
//by listening to the whole Document, you can add other things that
//dispatch Character events on the display list, like a keyboard listener
addEventListener(CharacterEvent.UP, moveCharacterUp);
//listeners for the rest of the character events...
}
public function moveCharacterUp(e:CharacterEvent):void {
//character move logic
}
//other handlers
}
}
Personally, I'd just add the navBar to the stage, and then there's no need to manage it at all (not even reference it with a variable), simply add the event listeners for the various character events.
The root of your problem doesn't seem to be the character code. However, I'm going to give you a few "best practice" pointers about it.
The convention in AS3 is for Class members (properties and methods) to be camel case starting with a lower case letter. So, characterPos() and characterMove().
Your Class already contains character in the name, so really these should just be pos() and move() (though there's no need now to shorten position()).
The only thing your child Classes are doing with their references to the parent are adding themselves. They don't need and shouldn't have a reference to the parent for this purpose. It is the parent's responsibility to add the Children (or the responsibility of the Flash Player if you use the stage).
That said, you could give your Character a reference to the parent Class typed as IEventDispatcher and allow the Character to listen to this channel. This concept is called an event bus.
Note that the reason that so many people do what you're doing is that Adobe failed to document how to properly use OOP with the timeline. Unfortunately, by the time a few of us started documenting that around late 2009/early 2010, the damage was done and everyone assumed that if you wanted to write good code you had to pretend the timeline and stage didn't exist.
I know I've covered a lot of ground, and probably most of what I said directly contradicts what you thought you knew, so please don't hesitate to ask any questions you might have.

Constructor arguments problem ActionScript 3

I have a custom class defined in Actionscript and I want to make an instance of it in the main document of Flash application. However, after calling the constructor with one argument, Flash gives me this error:
Error #1063: Argument count mismatch on coa.application::MenuItem(). Expected 1, got 0.
This is my class:
public class MenuItem extends MovieClip{
var button:SimpleButton;
public function MenuItem(buttonLoc:uint) {
button = new InvBtn();
this.addChild(button);
button.x=-81;
button.y=buttonLoc*33;
button.addEventListener(MouseEvent.CLICK, mybringToFront);
}
}
And this is my attempt to call its constructor:
var menu1:MovieClip = new MenuItem(3);
Any idea, whats wrong?
Apologies, I can't comment yet, or I'd put this in a comment.
Are you sure that:
var menu1:MovieClip = new MenuItem(3);
is the only place that you're constructing a new MenuItem? You don't by any chance have the MenuItem class attached to some instances on the stage?
I changed your code to this (just so I could run it) and it works fine:
package{
import flash.display.MovieClip;
import flash.display.SimpleButton;
import flash.events.MouseEvent;
public class MenuItem extends MovieClip{
var button:SimpleButton;
public function MenuItem(buttonLoc:uint) {
button = new SimpleButton();
this.addChild(button);
button.x=-81;
button.y=buttonLoc*33;
button.addEventListener(MouseEvent.CLICK, mybringToFront);
}
public function mybringToFront(event:MouseEvent):void{
trace('blah');
}
}
}
Like quoo said, most likely you have an instance of the object that the class is attached to on stage. To test for that do this:
public class MenuItem extends MovieClip{
var button:SimpleButton;
// I changed it to int, cuz uint is extremely slow for any math
// other than bitwise operators, int is fast as long as no fractions
public function MenuItem(buttonLoc:int = -1) {
if (buttonLoc == -1)
trace("On stage instance found! Location: "+x+", "+y);
button = new InvBtn();
this.addChild(button);
button.x=-81;
button.y=buttonLoc*33;
button.addEventListener(MouseEvent.CLICK, mybringToFront);
}
}