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

Need to loop to certain point on mouse-click

New Here ,
Jun 19, 2012 Jun 19, 2012

Copy link to clipboard

Copied

Hello,

for work I am trying to create a visual for a simple electric circuit. What I want is that when the circuit opening is clicked, it closes and the light bulb comes on. When it is clicked again, it opens and the light bulb turns off.

Untitled.png


I have it working fine when I try to play it one time through. However, I do not know how to send it back to the beginning and run through the entire timeline again.

On frame 1 I have this actionscript:

stop();

movieClip_1.addEventListener(MouseEvent.CLICK, fl_ClickToGoToAndPlayFromFrame_3);

function fl_ClickToGoToAndPlayFromFrame_3(event:MouseEvent):void
{
gotoAndPlay(2);
}

This plays till frame 11, which has the script:

movieClip_1.addEventListener(MouseEvent.CLICK, fl_ClickToGoToAndPlayFromFrame);

function fl_ClickToGoToAndPlayFromFrame(event:MouseEvent):void
{
gotoAndPlay(13);
}

stop();

It then plays till the end (frame 24), where I put in the script:

movieClip_1.addEventListener(MouseEvent.CLICK, fl_ClickToGoToAndPlayAtFrame);

function fl_ClickToGoToAndPlayAtFrame(event:MouseEvent):void
{
gotoAndPlay(2);
}

Everything works great, even when it is sent back to frame 2. The problem is that when it reaches 11 again, clicking the mouse always sends it back to 2 instead of on to 13.

I hope this makes sense, I don't really know any better ways to explain it. It's probably a simple fix, but I'm new to actionscript and this has been driving me crazy. Any help would be appreciated.

Thanks,

Emily

TOPICS
ActionScript

Views

888

Translate

Translate

Report

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 ,
Jun 19, 2012 Jun 19, 2012

Copy link to clipboard

Copied

When you keep adding event listeners to the same object, they all stay, which is probably causing problems for you.  What you should do is only assign the event listener once in frame 1 and only define the event handler function once there as well.  In the event handler function use a variable for the frame that you go to, and change the value of that variable in the different frame that you stop in.

Votes

Translate

Translate

Report

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
New Here ,
Jun 19, 2012 Jun 19, 2012

Copy link to clipboard

Copied

I'm not quite sure what I'm doing, but this is what I have so far:

in frame 1:

stop();
{
movieClip_1.addEventListener(MouseEvent.CLICK,event_handler);

function event_handler(event:MouseEvent):void
{
var i:int = this.currentFrame;
{
if (1)
gotoAndPlay(2);
}
{
if (11)
gotoAndPlay(12);
}
{
if (24)
gotoAndPlay(2);
}
}
}

I also have the stop(); command in frames 11 and 24.

The issue I'm having now is that, when clicked, the animation always plays frames 2-11. It seems to only recognize the first variable value and none of the others.

Votes

Translate

Translate

Report

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 ,
Jun 19, 2012 Jun 19, 2012

Copy link to clipboard

Copied

LATEST

use:

stop();
{
movieClip_1.addEventListener(MouseEvent.CLICK,event_handler);

function event_handler(event:MouseEvent):void
{
var i:int = this.currentFrame;
{
if (i==1)
gotoAndPlay(2);
}
{
if (i==11)
gotoAndPlay(12);
}
{
if (i==24)
gotoAndPlay(2);
}
}
}

Votes

Translate

Translate

Report

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 ,
Jun 19, 2012 Jun 19, 2012

Copy link to clipboard

Copied

use:

On frame 1 I have this actionscript:

stop();

movieClip_1.addEventListener(MouseEvent.CLICK, fl_ClickToGoToAndPlayFromFrame_3);

function fl_ClickToGoToAndPlayFromFrame_3(event:MouseEvent):void
{
gotoAndPlay(2);
}

This plays till frame 11, which has the script:

movieClip_1.addEventListener(MouseEvent.CLICK, fl_ClickToGoToAndPlayFromFrame);

function fl_ClickToGoToAndPlayFromFrame(event:MouseEvent):void
{
gotoAndPlay(13);
}

stop();

It then plays till the end (frame 24), where I put in the script:

movieClip_1.addEventListener(MouseEvent.CLICK, fl_ClickToGoToAndPlayAtFrame24);

function fl_ClickToGoToAndPlayAtFrame24(event:MouseEvent):void
{
gotoAndPlay(2);
}

Everything works great, even when it is sent back to frame 2. The problem is that when it reaches 11 again, clicking the mouse always sends it back to 2 instead of on to 13.

I hope this makes sense, I don't really know any better ways to explain it. It's probably a simple fix, but I'm new to actionscript and this has been driving me crazy. Any help would be appreciated.

Thanks,

Emily

Votes

Translate

Translate

Report

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