Skip to main content
March 8, 2011
Answered

Code works on one frame but not the other

  • March 8, 2011
  • 2 replies
  • 1042 views

I have 2 frames in my movie, 2 buttons and a video.  On the first frame there is code for button #1.  On the second frame i have code for button #2 but I'd also like to appear on the first frame. The problem is that when I put the code for the second button on the first frame, the video won't play.  so I can only have it on the second frame.  I can't figure out why the code, which works when its on frame 2, then won't work on frame 1.  When I put the code on frame 1 it breaks the functionality and the video won't play.

This is the code on frame 1, for button #1 (btn_skip) :

stop();

btn_skip.addEventListener(MouseEvent.CLICK, fl_ClickToGoToWebPage_2);

function fl_ClickToGoToWebPage_2(event:MouseEvent):void

{

navigateToURL(new URLRequest("http://www.brokerschoice.com/Black_Vault/innervault.html"), "_self");

}

import fl.video.MetadataEvent;

mymovie.addEventListener(MetadataEvent.CUE_POINT, fl_CuePointHandler_2);

function fl_CuePointHandler_2(event:MetadataEvent):void

nextFrame();

This is the code on frame 2, for button #2 (btn_skip) : This code works if I put it on frame 2, but breaks the video if I put it on frame 1. I need to have this code on frame 1 as well.

btn_homePage.addEventListener(MouseEvent.CLICK, fl_ClickToGoToWebPage_3);

function fl_ClickToGoToWebPage_3(event:MouseEvent):void

{

navigateToURL(new URLRequest("http://www.brokerschoice.com"), "_blank");

}

thanks

This topic has been closed for replies.
Correct answer kglad

i'm confused by what you mean by "move" vs "duplicate".   I "cut" the code from one frame and pasted it into the other. 

thanks


if that were true you wouldn't have a duplicate function error.  or, the error is unrelated to anything i suggested.

in any case, fix that  so you don't have two identical function names.

2 replies

kglad
Community Expert
Community Expert
March 8, 2011

create a new layer.  cut and paste (in place) your on-stage btn_homePage from frame2  to frame 1 of the new layer.  move that button's listener code and function to frame 1.

March 8, 2011

OK, I think I did what you suggested but it still doesn't work.  I put the button on a new layer (btn_home).  I then put the code below on the new layer on which the button is. But the video is breaks again and doesn't appear.  I also get this compiler error, which I don't understand: "Scene 1, Layer 'btn2', Frame 1, Line 12 1021: Duplicate function definition."

btn_homePage.addEventListener(MouseEvent.CLICK, fl_ClickToGoToWebPage_3);

function fl_ClickToGoToWebPage_3(event:MouseEvent):void

{

navigateToURL(new URLRequest("http://www.brokerschoice.com"), "_blank");

}

thanks for your help!

kglad
Community Expert
Community Expert
March 8, 2011

"move" the code, don't duplicate the code.

Chipleh
Inspiring
March 8, 2011

Try putting your function on frame 1:

function fl_ClickToGoToWebPage_3(event:MouseEvent):void

{

     navigateToURL(new URLRequest("http://www.brokerschoice.com"), "_blank");

}

And then just your event handler on frame 2:

btn_homePage.addEventListener(MouseEvent.CLICK, fl_ClickToGoToWebPage_3);
Per your description, the function doesn't work on frame 1 because it doesn't exist on frame 1. Initiate your code on the first frame, and just apply the eventListener to objects on the frames where they will be called from...if that makes any sense.
~chipleh