PDA

View Full Version : help with class error



itzallme
June 8th, 2009, 12:13 AM
Button class:


package
{

import flash.display.Sprite;
import flash.text.*;
import gs.*;
import flash.events.MouseEvent;

public class Button extends Sprite
{

public var _label:String;
private var box:Sprite;
private var boxOver:Sprite;
private var menu:TextField;


function Button(label:String)
{

_label = label;

createbox();
createboxOver();
createmenu();




addChild(box);
addChild(boxOver);
addChild(menu);


}

private function createbox(){

box = new Sprite();
box.graphics.beginFill(0xcccccc);
box.graphics.drawRect(0,0,160,24);
box.graphics.endFill();

}

private function createboxOver(){

boxOver = new Sprite();
boxOver.graphics.beginFill(0x990000);
boxOver.graphics.drawRect(0,0, 160, 24);
boxOver.graphics.endFill();
boxOver.scaleX=0;

}


private function createmenu(){

menu = new TextField();
menu.text = _label;
menu.x=boxOver.x+2;
menu.y=boxOver.y+2;

}


public function events(e:MouseEvent){

box.addEventListener(MouseEvent.ROLL_OVER, overHandler);
box.addEventListener(MouseEvent.ROLL_OUT, outHandler);

}

public function overHandler(e:MouseEvent):void{

TweenLite.to(boxOver, .5, {scaleX:1});

}

public function outHandler(e:MouseEvent):void{

TweenLite.to(boxOver, .5, {scaleX:0});

}

}

}
Document frame 1 as:


var butn:Button = new Button("hello");
addChild(butn);
butn.x=100;
butn.y=100;




The Roll Over and Roll Out State isn't working.



Please help thanks!

Alpha Remex
June 8th, 2009, 12:26 AM
I think it's the line that says "label;" instead of "this.label = label;"

itzallme
June 8th, 2009, 12:42 AM
I edited the code again and got it working, but the Mouse_Over and Mouse_Out isn't working. Please help

itzallme
June 8th, 2009, 01:55 AM
Solved!! =]