Using frame labels to jump forward/backwards in a movieclip?

kmead6
kmead6 used Ask the Experts™
on
Hello! I have a .fla I'm working on that is a .swf with a .flv embedded in it and below the .flv are a series of 8 facts that loop in order. The "facts" are inside a movieclip called "facts_mc". As you can see in my code below I have a play and pause button set up for the movieclip, which works fine and doesn't interfere with the .flv playback. My question is this: I'm trying to add skip forward/skip backward buttons ("ff_btn" and "rw_btn") that will skip to the next fact inside the movieclip. I've assigned frame labels to the beginning of each of the facts ("fact1" "fact2" etc through "fact 8"). I believe I can do this with an array and assign the variable i and add something like:

if (pEvent.target == rw_btn)
{
gotoAndStop("Name of Array"[-i])
}

to my function, right?

I'm just not sure how to do this or what the code would be exactly for the array and defining "i". I've tried some code I've found off the internet but when I pasted it in and redefined some of the variables it didn't work in my .swf when I tested it and made my .flv go away.

Any help would be greatly appreciated! I'm working in CS3/AS3.
play_btn.visible = false;
ff_btn.visible = false;
rw_btn.visible = false;
 
function buttonClick(pEvent:MouseEvent):void
{
	if(pEvent.target == pause_btn)
	{
		facts_mc.stop();
		pause_btn.visible = false;
		play_btn.visible = true;
		rw_btn.visible = true;
		ff_btn.visible = true;
	}
	else if(pEvent.target == play_btn)
	{
		facts_mc.play();
		play_btn.visible = false;
		rw_btn.visible = false;
		ff_btn.visible = false;
		pause_btn.visible = true;
	}
};
 
pause_btn.addEventListener(MouseEvent.MOUSE_CLICK, buttonClick);
play_btn.addEventListener(MouseEvent.MOUSE_CLICK, buttonClick)

Open in new window

Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Top Expert 2009
Commented:
Here is the edited code. It is not optimised because I want to make the code resembles more to the original. If I happen to misinterpret what you want, please tell me.

play_btn.visible = false;
ff_btn.visible = false;
rw_btn.visible = false;
 
var factIndex:int = 1;
 
function buttonClick(pEvent:MouseEvent):void
{
        if(pEvent.target == pause_btn)
        {
                facts_mc.stop();
                pause_btn.visible = false;
                play_btn.visible = true;
                rw_btn.visible = true;
                ff_btn.visible = true;
        }
        else if(pEvent.target == play_btn)
        {
                facts_mc.play();
                play_btn.visible = false;
                rw_btn.visible = false;
                ff_btn.visible = false;
                pause_btn.visible = true;
        }
        else if(pEvent.target == rw_btn)
        {
                if (factIndex > 1)
                {
                        factIndex--;
                        facts_mc.gotoAndStop("fact" + factIndex);
                }
        }
        else if(pEvent.target == ff_btn)
        {
                if (factIndex < 8)
                {
                        factIndex++;
                        facts_mc.gotoAndStop("fact" + factIndex);
                }
        }
};
 
pause_btn.addEventListener(MouseEvent.MOUSE_CLICK, buttonClick);
play_btn.addEventListener(MouseEvent.MOUSE_CLICK, buttonClick);
ff_btn.addEventListener(MouseEvent.MOUSE_CLICK, buttonClick);
rw_btn.addEventListener(MouseEvent.MOUSE_CLICK, buttonClick);

Open in new window

Author

Commented:
this is similar to what I was trying and for some reason it's not working. I'll attach the fla file if that helps but the .flv it's connected to will be missing. There's something that happens when I add the index variable that just seems to cause everything else to stop working. so strange.
Flash-EE.fla.txt
Top Expert 2009

Commented:
I have tested and the code works fine. Just that whenever when the facts_mc is playing, it must add the index when it reaches a new fact, otherwise it will not synchronise properly with the ff_btn and rw_btn.

Everything else is working fine, what problems do you get?

Edit the .fla with the new code and test again, if there is still a problem, then describe the problem fully and post the .fla.
Success in ‘20 With a Profitable Pricing Strategy

Do you wonder if your IT business is truly profitable or if you should raise your prices? Learn how to calculate your overhead burden using our free interactive tool and use it to determine the right price for your IT services. Start calculating Now!

Author

Commented:
below is my new code in it's entirety. i didn't include it all originally because i didn't think the other function would be relevant, but it's part of what is getting affected. with this new code the first function (for an interactive map) becomes defunct, and instead of the FLV being displayed with its skin I get a FLV icon that flashes on and off repeatedly. I posted the .fla above with the added extension of .txt for upload sake.
thanks so much for taking the time to help a noob =)
wayne.visible = false;
chinatown.visible = false;
eureka.visible = false;
lotus.visible = false;
play_btn.visible = false;
ff_btn.visible = false;
rw_btn.visible = false;
 
function handleClick(pEvent:MouseEvent):void
{
	if(pEvent.target == wayne_btn)
	{
		wayne.visible = true;
		chinatown.visible = false;
		eureka.visible = false;
		lotus.visible = false;
	}
	else if(pEvent.target == chinatown_btn)
	{
		chinatown.visible = true;
		wayne.visible = false;
		eureka.visible = false;
		lotus.visible = false;
	}
	else if(pEvent.target == eureka_btn)
	{
		eureka.visible = true;
		wayne.visible = false;
		chinatown.visible = false;
		lotus.visible = false;
	}
	else if(pEvent.target == lotus_btn)
	{
		lotus.visible = true;
		wayne.visible = false;
		chinatown.visible = false;
		eureka.visible = false;
	}
	else if(pEvent.target == mapLV_btn)
	{
		wayne.visible = false;
		chinatown.visible = false;
		eureka.visible = false;
		lotus.visible = false;
	}
};
 
var facts:Array = new Array("fact1", "fact2", "fact3", "fact4", "fact5", "fact6", "fact7", "fact8");
var factIndex:int = 1;
 
function buttonClick(pEvent:MouseEvent):void
{
	if(pEvent.target == pause_btn)
	{
		facts_mc.stop();
		pause_btn.visible = false;
		play_btn.visible = true;
		rw_btn.visible = true;
		ff_btn.visible = true;
	}
	else if(pEvent.target == play_btn)
	{
		facts_mc.play();
		play_btn.visible = false;
		rw_btn.visible = false;
		ff_btn.visible = false:
		pause_btn.visible = true;
	}
    else if(pEvent.target == rw_btn)
    {
        if (factIndex > 1)
        {
			factIndex--;
            facts_mc.gotoAndStop("fact" + factIndex);
                }
        }
        else if(pEvent.target == ff_btn)
        {
                if (factIndex < 8)
                {
                        factIndex++;
                        facts_mc.gotoAndStop("fact" + factIndex);
                }
        }
};
 
wayne_btn.addEventListener(MouseEvent.CLICK, handleClick);
chinatown_btn.addEventListener(MouseEvent.CLICK, handleClick);
eureka_btn.addEventListener(MouseEvent.CLICK, handleClick);
lotus_btn.addEventListener(MouseEvent.CLICK, handleClick);
mapLV_btn.addEventListener(MouseEvent.CLICK, handleClick);
pause_btn.addEventListener(MouseEvent.MOUSE_CLICK, buttonClick);
play_btn.addEventListener(MouseEvent.MOUSE_CLICK, buttonClick);
ff_btn.addEventListener(MouseEvent.MOUSE_CLICK, buttonClick);
rw_btn.addEventListener(MouseEvent.MOUSE_CLICK, buttonClick);

Open in new window

Top Expert 2009

Commented:
I found your problem.

pause_btn.addEventListener(MouseEvent.MOUSE_CLICK, buttonClick);
play_btn.addEventListener(MouseEvent.MOUSE_CLICK, buttonClick);
ff_btn.addEventListener(MouseEvent.MOUSE_CLICK, buttonClick);
rw_btn.addEventListener(MouseEvent.MOUSE_CLICK, buttonClick);

It's MouseEvent.CLICK, not MouseEvent.MOUSE_CLICK, didn't you see those errors appearing when you compile?

Author

Commented:
whoops! i think i've been staring at this project for too long! strangely enough they weren't showing up in the compiler. thanks again!
Top Expert 2009

Commented:
I didn't notice it at first too as you can see from my edited solution.

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial