View Full Version : Actionscript Question Concerning Buttons within Movie Clips
Huston
January 14th, 2004, 11:18 AM
Hi guys,
Being rather "green" with actionscripting, I am having difficulties using a sliding menu (very similar to the "infinite menu" tutorial here on kirupa) in conjuction with some actionscripting to interact with some external movies outside the main movie I am working with. What I want to do is to use each button within the menu to reference a flash movie outside the menu bar (which is a movie clip). Before I sound even more vague let me show you the code first....
aboards.onRelease = function() {
loadMovie("aboard.swf", "target");
};
So here I have a button instance (aboards) of one of the 10 buttons in the menu. I want to then reference a movie clip called "target" in the main scene of my movie to then load and display the movie aboard.swf at this reference point.
This code works well with static buttons on the main scene, but here each of the 10 buttons are located within the movie clip that makes the sliding menu work.
The instance "aboards" of course works if I assign the instance to the movie clip, but then that of course means that ALL 10 buttons then will be assigned "aboards". What code change can I make to fix this issue so that each of the 10 buttons (within the movie clip) carry their own instance that can be referenced from the main scene?
Help!:beer: TIA.
B. Huston
boyzdynasty
January 14th, 2004, 11:31 AM
I'm not sure I follow you...
just to clarify....
You have a Main Movie.
Then you have two MCs. One MCcontains a button (aboards)?
And another MC called "target" , which is use to load whatever in it?
BTW:I'm not familiar w/ the tutorial.
Voetsjoeba
January 14th, 2004, 11:34 AM
So you assigned the onRelease handler to the movieclip containing the buttons, not on the buttons themselves ? If so, then you need assign it to the buttons:
aboards.btn1.onRelease = function(){
target.loadMovie("movie1.swf");
}
aboards.btn2.onRelease = function(){
target.loadMovie("movie2.swf");
}
//...
Huston
January 14th, 2004, 11:43 AM
So you assigned the onRelease handler to the movieclip containing the buttons, not on the buttons themselves ? If so, then you need assign it to the buttons:
No, I assigned it to the buttons, but didn't know the syntax to properly relate to the movie clip that handles them.
For example I tried something similar to your suggestion that looked like the following:
1.aboards.onRelease = function(){
loadMovie("aboards.swf", "target");
Where "1" is the instance of the movie clip (menu slider) and "aboards" is the instance of the button. When I do this I get the following error messages during testing:
Scene=Scene 1, Layer=Layer 5, Frame=1: Line 4: ';' expected
1.aboards.onRelease = function(){
FYI, "target" in above code is the "tell target" MC on the main where the movie is to load.
B. Huston
Huston
January 14th, 2004, 11:48 AM
I'm not sure I follow you...
just to clarify....
You have a Main Movie.
Then you have two MCs. One MCcontains a button (aboards)?
And another MC called "target" , which is use to load whatever in it?
Sorry for being less than clear. I have two MCs on the main movie one is "target" that is empty and loads in a movie called, the other is the menu slider that contans the 10 buttons that I want to code so that they will load a movie into the MC called target.
Thanks for the help, it is deeply appreciated....
B. Huston
boyzdynasty
January 14th, 2004, 11:54 AM
it's a path issue...
try using "_root.target"
boyzdynasty
January 14th, 2004, 11:55 AM
oh...and...
if aboards is the instance name of the button, can you tell me where this code is located?
Is it in the Main Time Line? If so, it should be MCinstannceName.aboards......
If the code is located in the MC, then it should be aboards.onRelease
boyzdynasty
January 14th, 2004, 11:57 AM
you can post the fla if you still have trouble...
Huston
January 14th, 2004, 11:58 AM
Do you mean:
1.aboards.onRelease = function(){
loadMovie("aboards.swf", "_root.target");
If so, I get the some error as above...
B.Huston
boyzdynasty
January 14th, 2004, 12:01 PM
it depends where the code is.
did you try it with just
aboards.onRelease = function(){
loadMovie("aboards.swf", "_root.target");
}
Huston
January 14th, 2004, 12:01 PM
you can post the fla if you still have trouble...
www.bradhuston.com/products2.fla
did you try it with...
Yeah, same issue. This one is going to make all my hair fall out...
:P
B. Huston
boyzdynasty
January 14th, 2004, 12:04 PM
i'll take a look
btw: you can't have an instance name that starts with a number.
boyzdynasty
January 14th, 2004, 12:09 PM
you don't have any buttons... they are just text fields. you need to convert it to buttons.
Huston
January 14th, 2004, 12:18 PM
you don't have any buttons...
boyz...
Try clicking outside the text box, the buttons are "underneath" so to speak.
btw: you can't have an instance name that starts with a number.
Okay, thanks.
B.Huston
boyzdynasty
January 14th, 2004, 12:36 PM
oh...i see...
i'm gonna go have lunch...will check on it when I get back.
PM me your e-mail so I can send you the *fla with the changes.
boyzdynasty
January 14th, 2004, 12:46 PM
n/m...here is what i did...
the main MC that holds the slider...
I gave it an instance name called mainslide
then in the mainslider movie clip I name the both the MCs in there... slider1 (I assume they have the same purpose).
Now in the frame with the action i have this
onload = function () {
loadMovie("pintro.swf", "target");
};
mainslide.slide1.aboards.onRelease = function(){
loadMovie("aboards.swf", "_root.target");
}; // you missed a closing brace :-p
mainslide.slide1.banners.onRollOver = function() {
loadMovie("banners.swf", "_root.target");
};
mainslide.slide1.directory.onRollOver = function() {
loadMovie("directory.swf", "_root.target");
};
mainslide.slide1.political.onRollOver = function() {
loadMovie("political.swf", "_root.target");
};
mainslide.slide1.jobsite.onRollOver = function() {
loadMovie("jobsite.swf", "_root.target");
};
mainslide.slide1.transport.onRelease = function() {
loadMovie("transport.swf", "_root.target");
};
mainslide.slide1.realestate.onRelease = function() {
loadMovie("realestate.swf", "_root.target");
};
mainslide.slide1.vehicle.onRelease = function() {
loadMovie("vehicle.swf", "_root.target");
};
mainslide.slide1.storefront.onRelease = function() {
loadMovie("storefront.swf", "_root.target");
};
mainslide.slide1.dimension.onRelease = function() {
loadMovie("dimension.swf", "_root.target");
};
Huston
January 14th, 2004, 02:21 PM
:*(
boyz,
Thanks. I found that this resolves the issue concerning the instances (it is why some of the buttons are coded OnRollOver so I could check to see if this part of the code was working) and the buttons. I am working on resolving a new issues that have come up....
Many thanks again for looking at it...
, but I am going to try and resolve it on this end first, before I continue to waste the boards time....
B. Huston
Huston
January 14th, 2004, 02:53 PM
Okay, now the buttons within the movie clip work, but ONLY to the left of x=300 (actually at various points x<300 depending on the button) which correlates to the direction the slider works given the mouses movement right or left. Why the code only works to the left of x=300, is beyond me. Any thoughts? Here's the code for the slider (Boyz, the movie clip you named as mainslide)
onClipEvent (load)
{
xcenter=300;
speed=1/35;
}
onClipEvent (enterFrame)
{
var distance=_root._xmouse-xcenter;
_x+=(distance*speed);
if (_x > 0) _x=-600;
if (_x < -600) _x=0;
}
Here's an updated version of this movie:
www.bradhuston.com/product2.fla
Huston
January 14th, 2004, 04:09 PM
Never mind the above. I figured it out. I needed to duplicate the code and change the second slider1 to 2 and modify the code to reflect the buttons in slider2, it works perfectly now. Thanks to all.
B.Huston
boyzdynasty
January 14th, 2004, 04:54 PM
i just woke up :D and I was reading your post....and I was looking at the question...
Then I was like...hmmm...maybe I should see the last post.
And it was good news! hehe
Good Job.
Keep it up and you'll be a pro in no time.
Powered by vBulletin® Version 4.1.10 Copyright © 2012 vBulletin Solutions, Inc. All rights reserved.