Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Trying to load a library image with toggle button

Explorer ,
Feb 13, 2018 Feb 13, 2018

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.

335
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Explorer , Feb 13, 2018 Feb 13, 2018

THANK YOU.  Worked PERFECT and I learned something as well.

Translate
Community Expert ,
Feb 13, 2018 Feb 13, 2018

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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Feb 13, 2018 Feb 13, 2018

THANK YOU.  Worked PERFECT and I learned something as well.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Feb 13, 2018 Feb 13, 2018
LATEST

This is great!

You're welcome!

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines