Skip to main content
Inspiring
February 24, 2010
Question

going down in heirarchy to build buttons

  • February 24, 2010
  • 1 reply
  • 277 views

I want to put togther a set of buttons built with my generic button class that is put on the stage with the  main class.

Here is what I have put together so far.  The GButton class works just great, but going from there up I am having a problem.

MyButtons.as  the main file that will present the button set on the stage
package
{
import flash.display.*;
import flash.events.*;
public class MyButtons extends MovieClip
{
  public var baseball:ButtonSet = new ButtonSet

("images/baseball.gif","baseleft","baseright");
 
  public function MyButtons()
  {
   init();
  }
  public function init()
  {
   //trace("got to the init function");
   baseball.x = 200; baseball.y = 200; baseball.visible = true;

  }
}
}


Gbutton.as  my generic button class which works just fine
package
{
import flash.display.*; //brings in functions or classes that are needed for

displaying things
import flash.events.*; // brings in functions or classes  that are needed for

things to happen
import flash.net.URLRequest; // brings in functions that work with outside files
import caurina.transitions.Tweener;// brings in the tweener class to work with

properties of objects
import caurina.transitions.properties.ColorShortcuts;// bring in specialized

tweener class to work with specific properties
ColorShortcuts.init();// sets up the specialized tweener class
// *************************** creates the class and sets up memory to be used by

it ********************
public class GButton extends MovieClip
{
  public var thename:String = new String;
  public var buttonPic:Loader = new Loader(); // creates the area in memory

for the picture to come into
  private var lineDrawing:MovieClip = new MovieClip(); // creats an are in

memory to hold the information concerning the box
  // *********************************** creates the function that puts the

button together ************
  public function GButton(thumbpic:String, whatname:String)
  {
   buttonPic.load(new URLRequest(thumbpic));// loads the picture from

the external file
   thename = whatname;
   this.buttonMode = true; // makes it so that the movie clip

functions as a button
   this.addEventListener(MouseEvent.MOUSE_OVER, getOver); // listens

to hear if the mouse is within the button's area
   this.addEventListener(MouseEvent.MOUSE_OUT, getOut); // listens to

hear if the mouse is outside the button's area
   this.addChild(buttonPic); // adds this button to the stage or

display list
   this.mouseChildren = false; // ensures that items within the button

do not get recognized by the mouse
  }
// ********************************* creates the function that works when the mouse

is in the button's area *************
  private function getOver(e:Event)
  {
   this.addChild(lineDrawing); // adds the box to the stage
   lineDrawing.graphics.lineStyle(2); // selects the width of the line

for the box
   lineDrawing.graphics.moveTo(buttonPic.x,buttonPic.y); // This is

where we start drawing at the button's 0x and 0y
   lineDrawing.graphics.lineTo(buttonPic.x,buttonPic.y +

buttonPic.height); // draws the line  along the left side of the button
   lineDrawing.graphics.lineTo(buttonPic.x + buttonPic.width

,buttonPic.y + buttonPic.height); // draws the line along the bottom of the button
   lineDrawing.graphics.lineTo(buttonPic.x +

buttonPic.width,buttonPic.y); // draws the line along the right side of the button
   lineDrawing.graphics.lineTo(buttonPic.x,buttonPic.y); // finishes

drawing the box by going back to the original position
   this.lineDrawing.visible = true; // allows the box to be seen
   Tweener.addTween(this, {_brightness:.55, delay:.5}); // changes the

brightness of the picture by 55%
  } // end of getOver function
// ******************************** creates the function that works when the mouse

goes outside the button's area ***********
  private function getOut(e:Event)
  {
   this.lineDrawing.visible = false; // does not allow the box to be

seen
   Tweener.addTween(this, {_brightness:0, delay:1}); // puts the

brightness of the button back to its original setting
  } // end of getOut function
} // end of class area
} // end of package area


ButtonSet.as  a class I am trying to make from my generic class
package
{
import flash.display.MovieClip;
import flash.display.SimpleButton;
import flash.display.Shape;
import flash.events.Event;
import flash.events.MouseEvent;
import flash.text.*;
import GButton;
public class ButtonSet extends MovieClip
{
 
 
 
  public function ButtonSet

(pictureFile:String,buttonName1:String,buttonName2:String)
  {
   var leftButton:GButton = new GButton(pictureFile,buttonName1);
   var rightButton:GButton = new GButton(pictureFile,buttonName2);
   //var theText:TextField = new TextField();
   addChild(leftButton);
   addChild(rightButton);
   //addChild(theText); theText.x = 0; theText.y = 100;

theText.visible = true;
  }
 
}
}

Any suggestions?

This topic has been closed for replies.

1 reply

rebarrAuthor
Inspiring
February 24, 2010

Sorry, once again I figured it out.