Copy link to clipboard
Copied
I am new to ActionScript 3. I created a simple button that I imported into the stage and I named and saved it as Microwave_btn
and I wrote a simple script for it that says:
stop ();
import flash.display.*;
import flash.events.*;
Microwave_btn.addEventListener(MouseEvent.CLICK, Trace);
function Trace (event:MouseEvent): void {
trace("Microwave!");
}
The properties for the Microwave_btn has the
class labeled as: Microwave_btn
and the
Base class as: flash.display.SimpleButton
When I test the movie I get this error:
1061: Call to a possibly undefined method addEventListener through a reference with static type Class.
i assume this thread is closed and i see your other thread has a responder. good luck!
Copy link to clipboard
Copied
try:
import flash.display.*;
import flash.events.*;var btn:Microwave_btn=new Microwave_btn();
addChild(btn);
btn.addEventListener(MouseEvent.CLICK, Trace);
function Trace (event:MouseEvent): void {
trace("Microwave!");
}
Copy link to clipboard
Copied
Thank you so much. What I don't understand is that I have two buttons on my screen now and the button that works is located on the top left corner of my screen. My original button which is located on top of the background image (microwave) does not invoke the Microwave Trace function.
How do I get that to work and remove the Microwave_btn image from the top left corner of my screen and get original button to work?
Copy link to clipboard
Copied
the code i suggested created that top-left button. if you want to use the one on-stage, click it (to select it) and in the properties panel assign an instance name (eg, btn). you can then use:
btn.addEventListener(MouseEvent.CLICK, Trace);
function Trace (event:MouseEvent): void {
trace("Microwave!");
}
Copy link to clipboard
Copied
I have only one button on the stage which is the Micowave_btn. I also named the instance name for the button Microwave_btn.
When I try compiling the movie I get a new error message that says:
1046: Type was not found or was not a compile-time constant: Microwave_btn.
Copy link to clipboard
Copied
a class name can't be the same as an instance name. fix that and use the above code i suggested.
Copy link to clipboard
Copied
Ok! I reposted my question with screen shots at
http://forums.adobe.com/message/3200329#3200329
I changed the Microwave_btn instance name to microwave_mc and I still get two images of the Microwave_btn on the stage and the one at the top left corner works.
I would like tpl create 5 buttons total:
Dishwash_btn dishwash_mc (instance name)
Faucet_btn faucet_mc (instance name)
Microwave_btn microwave_mc (instance name)
Refrig_btn refrigwash_mc (instance name)
Stove_btn stove_mc (instance name)
If you read my reposted question you should be able to have a better understand of what I want to accomplish.
Copy link to clipboard
Copied
i assume this thread is closed and i see your other thread has a responder. good luck!
Copy link to clipboard
Copied
Copy link to clipboard
Copied
Thank you so much. What I don't
understand is that I have two buttons on my screen now and the button
that works is located on the top left corner of my screen. My original
button which is located on top of the background image (microwave) does
not invoke the Microwave Trace function. How do I get that to work and remove the Microwave_btn image from the top left corner of my screen and get original button to work?
Date: Mon, 11 Oct 2010 11:52:31 -0600
From: forums@adobe.com
To: edaddy@hotmail.com
Subject: Button error, 1061 error,
try:
import flash.display.*;
import flash.events.*;
var btn:Microwave_btn=new Microwave_btn();
addChild(btn);
btn.addEventListener(MouseEvent.CLICK, Trace);
function Trace (event:MouseEvent): void {
trace("Microwave!");
}
>