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

Help converting AS2 rollover buttons to AS3

Guest
Oct 05, 2010 Oct 05, 2010

This is probably a really dumb question, but I'm very new to AS3 so please bear with me. I created some rollover buttons (movieclips) for a flash website in AS2 using the following code:

onClipEvent (enterFrame) {
    this.onRollOver = function() {
    this.gotoAndPlay(1);
    }
}


onClipEvent (enterFrame) {
    this.onRollOut = function() {
    this.gotoAndStop(1);
    }
}

on (release){
    getURL("index.html", "_parent");
}

Could anyone advise me on how to start converting this code into AS3? I know I have to use an EventListener but I don't really understand how it works.

Any assistance would be greatly appreciated!

TOPICS
ActionScript
3.9K
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
LEGEND ,
Oct 05, 2010 Oct 05, 2010

Something like this:

this.addEventListener(MouseEvent.MOUSE_OVER, onMouseOver);
this.addEventListener(MouseEvent.MOUSE_OUT, onMouseOut);
this.addEventListener(MouseEvent.CLICK, onClick);

function onMouseOver(e:MouseEvent):void {
     this.gotoAndPlay(1);
}

function onMouseOut(e:MouseEvent):void {
     this.gotoAndStop(1);
}

function onClick(e:MouseEvent):void {
     navigateToURL(new URLRequest("index.html"), "_parent"));
}

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
Guest
Oct 06, 2010 Oct 06, 2010

Thank you very much for your help. Unfortunately it doesn't seem to be working for me. When I tried to test the movie I got the following error:

"WARNING: Actions on button or MovieClip instances are not supported in ActionScript 3.0. All scripts on object instances will be ignored."

Does this mean I can't add code to individual buttons/movieclips? How can I solve this problem?

Thanks

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
Guest
Oct 06, 2010 Oct 06, 2010

All your code has to be on frames, not on buttons or MovieClips.

There is no problem to solve. Just add your codes on frames.

Create an empty key frame and add:

button1.visible=false; // for example

so, at that frame button1will be invisible.

You don't need to write code on button1 like (as with AS2):

on (release){
    button1.visible=false;

}

Dont forget to name your instance as button1

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
Guest
Oct 06, 2010 Oct 06, 2010

Ok, so how do I go about modifying my code to suit every button?

I have added the following code to the first frame of my movie but it doesn't work. Any idea what I am doing wrong?

this.addEventListener(MouseEvent.MOUSE_OVER, onMouseOver);
this.addEventListener(MouseEvent.MOUSE_OUT, onMouseOut);
this.addEventListener(MouseEvent.CLICK, onClick);

function onMouseOver(e:MouseEvent):void {
    if (Link1.MOUSE_OVER == true) {
            Link1.gotoAndPlay(1);
    }
}

function onMouseOut(e:MouseEvent):void {
      if (Link1.MOUSE_OUT == true) {
          Link1.gotoAndStop(1);
      }
}

function onClick(e:MouseEvent):void {
    if (Link1.CLICK == true) {
        navigateToURL(new URLRequest("index.html"), "_parent");
    }
}

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
Guest
Oct 06, 2010 Oct 06, 2010

I have changed my code to:

Link1.addEventListener(MouseEvent.MOUSE_OVER, onMouseOver);
Link1.addEventListener(MouseEvent.MOUSE_OUT, onMouseOut);
Link1.addEventListener(MouseEvent.CLICK, onClick);

function onMouseOver(e:MouseEvent):void {
        Link1.gotoAndPlay(1);
}

function onMouseOut(e:MouseEvent):void {
          Link1.gotoAndStop(1);
}


function onClick(e:MouseEvent):void {
        Link1.navigateToURL(new URLRequest("index.html"), "_parent");
}

But it still doesn't work very well. The animation for the rollover keeps playing over and over, ignoring the "stop" I have within the frame of the movieclip.

You can view my website at: http://www.halopantryandgrill.com/test/index.php to get an idea of how my rollovers worked before. This was done in AS2.

I can't seem to get the same effect to work in AS3

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
Guest
Oct 06, 2010 Oct 06, 2010

Ok I *think* I have figured it out. I applied the following code to the first frame inside each button(movieclip) and it's working great. Thanks for everyone's help, I really appreciate it!

this.addEventListener(MouseEvent.ROLL_OVER, onMouseOver);
this.addEventListener(MouseEvent.ROLL_OUT, onMouseOut);
this.addEventListener(MouseEvent.CLICK, onClick);

function onMouseOver(e:MouseEvent):void {
    mouseEnabled = true;
    buttonMode = true;
    gotoAndPlay(1);
}

function onMouseOut(e:MouseEvent):void {
    gotoAndStop(1);
}


function onClick(e:MouseEvent):void {
    navigateToURL(new URLRequest("index.html"), "_parent");
}

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
Guest
Oct 06, 2010 Oct 06, 2010

it would be better to use all your code together on  one frame with using instance names.

(Much better control of your code and so no need for going into every movieclip to check its code)

If you thing question is answered please mark it please as answered.

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
Guest
Oct 06, 2010 Oct 06, 2010

Yes it probably would be better to do it that way. Though I am just happy at this stage to have got it working at all! lol.

For future reference can you give me an idea of how I could control all buttons from 1 frame?

Thanks

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
Guest
Oct 06, 2010 Oct 06, 2010
LATEST
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