Copy link to clipboard
Copied
This is the AS3 for working the button that I created and it works fine. However, I want something to happen and I put in the // in this code for what I need help with...
import flash.events.MouseEvent;
toggleButton.addEventListener(MouseEvent.MOUSE_OVER, rolloverToggle);
toggleButton.addEventListener(MouseEvent.MOUSE_OUT, rolloutToggle);
toggleButton.addEventListener(MouseEvent.CLICK, toggleClick);
toggleButton.buttonState = "on";
function rolloverToggle(event:MouseEvent) {
toggleButton.gotoAndStop(toggleButton.buttonState+ "over");
}
function rolloutToggle(event:MouseEvent) {
toggleButton.gotoAndStop(toggleButton.buttonState);
}
function toggleClick(event:MouseEvent) {
if (toggleButton.buttonState == "on"){
toggleButton.buttonState = "off";
//I want to load a png from library called MyImage1 to 0,0
}else {
toggleButton.buttonState = "on";
//I want to remove png called MyImage1 from stage
}
toggleButton.gotoAndStop(toggleButton.buttonState+ "over");
}
If there is an easier way to handle this, that's great. I just don't know if I need anything else to do this. I tried addChild, but not as though I know what I'm doing. In AS2 I didn't have this problem.
THANK YOU. Worked PERFECT and I learned something as well.
Copy link to clipboard
Copied
Hi.
This should do it:
import flash.events.MouseEvent;
import flash.display.BitmapData;
import flash.display.Bitmap;
var bitmap:Bitmap;
toggleButton.addEventListener(MouseEvent.MOUSE_OVER, rolloverToggle);
toggleButton.addEventListener(MouseEvent.MOUSE_OUT, rolloutToggle);
toggleButton.addEventListener(MouseEvent.CLICK, toggleClick);
toggleButton.buttonState = "on";
function rolloverToggle(event:MouseEvent)
{
toggleButton.gotoAndStop(toggleButton.buttonState + "over");
}
function rolloutToggle(event:MouseEvent)
{
toggleButton.gotoAndStop(toggleButton.buttonState);
}
function toggleClick(event:MouseEvent)
{
if (toggleButton.buttonState == "on")
{
toggleButton.buttonState = "off";
bitmap = new Bitmap();
bitmap.bitmapData = new MyImage1();
addChild(bitmap);
}
else
{
toggleButton.buttonState = "on";
if (bitmap)
removeChild(bitmap);
}
toggleButton.gotoAndStop(toggleButton.buttonState + "over");
}
I hope it helps.
Regards,
JC
Copy link to clipboard
Copied
THANK YOU. Worked PERFECT and I learned something as well.
Copy link to clipboard
Copied
This is great!
You're welcome!
Find more inspiration, events, and resources on the new Adobe Community
Explore Now