[MX04] Really easy if you know how- root.swf commmand?
Hi this is probably a really simple one to answer except i don't know actionscript so its like swahelli for me?! I have button that when hit needs to go to a label 'KC1'
This is what i have;
on (release) {
gotoAndPlay("KC1");
}
The problem is that my button is a very complicated one that involves buttons within buttons within mc's and the above code doesn't seem to be working; the button kind of refreshes itself- so its aknoledging that an action is supposed to be taking place but doesn't actualy take me to this label. I've tried to put;
on (release) {
_root.gotoAndPlay("KC1");
}
But this goes to the main movie timeline (my button is placed in an external swf loaded into my main movie and my button needs to link to a label within that swf not go to the root of the main movie)
You just have to specify the movieclip t in which you want to go to the label. You just have to write the name after the _root reference. this is the name you have given it if you click on the MC and look in the properties panel under "instance name".
Code:
on (release) {
_root.YourMovieclipName.gotoAndPlay("KC1");
}
If you are new to actionscript I would suggest, that you begin making our code a bit easier to read. Instead of putting the code on the buttons, you can write your code on the main timeline targeting the button with the punctation characters. this would look like this, if you have a button named "button1" inside a movieclip named "movieclip1":
It is so much easier to read, and you don't have to look around for the actionscript - you can put it all in a layer called "Actions" on the main timeline
Thank Ronze, I've now got it to work wihin its own movie but am having trouble when it loads into my main movie; perhaps something is needed like this?
on (release) {
_root.01a kitchens-cont.kitchen.swf.gotoAndPlay("KC1");
}
- '01a kitchens-cont.swf' is the movie in which my button has been placed (well actually its within a mc inside that swf called 'kitchen' So it works fine when i test it in its own movie but when i load that movie into my main movie as an external swf then the button won't link anymore?!
The problem is, that when you open 01a kitchens-cont.swf alone, the _root refers to it's own timeline. But when you load it into your main movie, the _root refers to the main timeline in the main movie - NOT the 01a kitchens-cont.swf timeline.
Instead of using _root you have to do another thing. (_root is not good to use, because as you can see it changes when you use multiple clips). You can use the _parent command. Let's say you have a movieclip called "Big" and a movieclip inside that one called "Small". Then you add this action to the "small" movieclips timeline.
Code:
_parent.gotoAndStop(3);
This will not gotoAndStop inside "Small" but gotoAndStop to frame 3 in its parent movieClip, that is "Big".
If your button is inside MC named "Kitchen" in your movie, you can just write:
Code:
on (release) {
_parent.gotoAndPlay("KC1");
}
The problem with the _root reference is, that if you change it to work when you load it into your main movie, then it won't work when you edit the "01a kitchens-cont.kitchen.swf " alone.
Just ask for questions, but try the _parent :-)
If it doesn't work then post your fla...
OK thanks for all this help; heres the fla i tried the parent method nothing happened, the fla is a little complicated- i've deleted the pics in the background to make the file smaller.
However to get to the code needed for this button you need to do the following (ps i can see the advantage of having all your code in the timeline now)
In the library open up the folder 'ranges' in there you will see a graphic called
'MENU-RANGE-KITCH-CONT' this is the one you'll need to access to change the code - each word is a button.
Last edited by deansawyer; 12-04-2007 at 06:43 PM.
I have been stuck on this for soooo long- thanks for taking the time to help me i out i really appreciate it, you guys on here are great.
If i could just pester you for another little bit of knowledge. If I press the button when i'm already on that page (as in i'm already on kc1 but i press the button to take me to kc1) it always takes me to the next label (in this case kc2) it doesn't just refresh that page. Any ideas on how to sort that out?
I've come across this problem so many times, generally i just put another keyframe in and then disable that button by making it a graphic instead of a button therefore the user can't press it. But in this case i can't do that.
You can check whether you already are in the frame, and only set the button to gotoAndPlay if it's not in the frame. Just find out the frame number of each frame label and type it in instead of framenumber underneath on each button.
Code:
on (release) {
if(_parent._parent._parent._currentframe != framenumber)
{
_parent._parent._parent.gotoAndPlay("KC1");
}
}
I'm not at my home computer right now, but it should work
I don't really know if you can use a label name, but search the help files, if _currentframe supports frame labels. Or else there should be some other command I don't know about :-)