Link to home
Create AccountLog in
Avatar of roscoeh23
roscoeh23

asked on

problem with buttons in AS3 - passing a function

I want to pass a variable with a button, the same way I do with a movie clip.Is there a way to do this?

Below is my code which gives the error



1119: Access of possibly undefined property myFrame through a reference with static type flash.display:SimpleButton.




my_but.myFrame = "theEnd";
 
myButton_but.addEventListener(MouseEvent.MOUSE_DOWN, nav)
 
 
function nav (event:MouseEvent) {
	
	trace(event.target.myFrame);
	
}

Open in new window

Avatar of Aneesh Chopra
Aneesh Chopra
Flag of India image

better way to create a variable in button scope and instead of passing to the function, just access it in function..

for example, follwoing code will work:

var myFrame = "theEnd";
myButton_but.addEventListener(MouseEvent.MOUSE_DOWN, nav)
 
function nav (event:MouseEvent) {
      trace(myFrame);
}

does the trace work ok if you just trace something static, like trace("hello"); ?

The event listener bit looks ok
Avatar of roscoeh23
roscoeh23

ASKER

but this means I cannot really expand it to 5 buttons without creating 5 functions which is what i have done.

I want to pass the variable and have 1 function.




face_but.addEventListener(MouseEvent.MOUSE_DOWN, goToFace);
hair_but.addEventListener(MouseEvent.MOUSE_DOWN, goToHair);
features_but.addEventListener(MouseEvent.MOUSE_DOWN, goToFeatures);
extras_but.addEventListener(MouseEvent.MOUSE_DOWN, goToExtras);
clothes_but.addEventListener(MouseEvent.MOUSE_DOWN, goToClothes);
finish_but.addEventListener(MouseEvent.MOUSE_DOWN, goToFinish);
 
 
 
function goToFace (event:MouseEvent) {
 
	this.gotoAndStop('face');
	
}
 
 
function goToHair (event:MouseEvent) {
 
	this.gotoAndStop('hair');
	
}
 
 
function goToFeatures (event:MouseEvent) {
 
	this.gotoAndStop('features');
	
}
 
function goToExtras (event:MouseEvent) {
 
	this.gotoAndStop('extras');
	
}
 
function goToClothes (event:MouseEvent) {
 
	this.gotoAndStop('clothes');
	
}
 
function goToFinish (event:MouseEvent) {
 
	this.gotoAndStop('finish');
	
}

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of Aneesh Chopra
Aneesh Chopra
Flag of India image

Link to home
membership
Create an account to see this answer
Signing up is free. No credit card required.
Create Account
Cool