Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 505
  • Last Modified:

call functions on root timeline from button within movie clip

Hi

I have set up fuctions and varibles in my root timeline for navigation around my site( i use them to tell me my current page and current content etc). I have a movie clip in which there is a quick link to my contacts page. i want to be able to run the functions i have set up from this button, so it can close the current content mc and so it will Know what page it is on when it opens the contact page.

I am fairly new to flash, i understand the priciples of _root when it comes to buttons within movie clips, but cant get my head around using the functions i have set up from a button within this mc.

Thanks



   
0
socross
Asked:
socross
  • 3
  • 2
2 Solutions
 
Ramy_atefCommented:
Hi

You should know that the Movie Clip has it own scope, meaning that if you wrote code on a movie clip or wrote a code on an button inside the button , then u are inside the scope of the Movie CLip, so if you want to call a function or a variable in the time line .. you use ( _root.myFunction() or _root.myVariable,...)

Form the other side, if you are in the main time line and  want to call a function or a variable from inside a MC , you just type the name of that MC instance first (the instance name not the symbol name) something like that
myMC.myFunction() or myMC.myVariable

that's it :)
hope I'm clear enough ...

Regards
Ramy
0
 
socrossAuthor Commented:
thanks that was what i was working at but i was trying to do it from the root timeline rather than from within the button.

Is it possible to code it from my root timeline, i like to have all my action script in the sameplace if i can

thanks.
0
 
Ramy_atefCommented:
Yes , so easy,
Say u have a movie clip on the stage , its instance name is :  myMC (not the symbol name)

in the main time line you cna write this

myMC.onRelease=function(){
      trace("I'm clicked")
}

Regards,
Ramy
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
socrossAuthor Commented:
sorry if i sound thick

what do you mean by  

trace("I'm clicked")

0
 
thesmallprintCommented:
The trace function is a debugging tool used by developers to output text when you compile your .swf with-in Flash, its an easy way to let you know if things are working or not ( in a sense! ).

in this case when your button is clicked Ramy_atef uses the "trace" function in flash to see if your button has been pressed.

Anyways back to your solution...

Try this its basic but edit it to your needs...

on the main _root put this code:-

stop();
function navigate(val1){
_root.gotoAndStop(val1);
}

Whilst still on the _root Make a button and put the following actionscript code on it:-

on(press){
_root.navigate(1);
}

now on your button whatever you set the number to is the frame which your movie will gotoAndStop(); at.

Now just re-use the same button through-out your flash document and if you want to change frames just add the code above to a button and change the number to the frame number you wish to be taken to.
0
 
Ramy_atefCommented:
Hi,
I meant by
trace("I'm clicked")

to make sure that the button is clicked , trace just gives you an output with whatever you write in it .. so in this case you will see "I'm clicked" in the output winodw in Flash, of course you can replace this function with whatever you like to do..

Regards,
Ramy
0

Featured Post

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now