View Full Version : Problem with a button inside of a movie clip!
ballerz4life
March 30th, 2009, 04:01 AM
I believe post should be in this sections since I am having problems with writing the script.
Forgive me if it is in the wrong section.
I am using Flash CS4. I am trying to get 4 buttons to work that are inside of a movie clip. I have read many suggestions but I am still not getting it to work.
Here are some of the things I have tried...
example1_btn.addEventListener(MouseEvent.CLICK, onExmp1Click);
example2_btn.addEventListener(MouseEvent.CLICK, onExmp2Click);
example3_btn.addEventListener(MouseEvent.CLICK, onExmp3Click);
example4_btn.addEventListener(MouseEvent.CLICK, onExmp4Click);
function onExmp1Click(e:MouseEvent):void
{
gotoAndStop("1")
}
function onExmp2Click(e:MouseEvent):void
{
gotoAndStop("2")
}
function onExmp3Click(e:MouseEvent):void
{
gotoAndStop("3")
}
function onExmp4Click(e:MouseEvent):void
{
gotoAndStop("4")
}
This is what is working for the buttons that are on the main timeline. I tried this inside of the movie clip on the actions layer without any luck.
Some said I could apply this directly to the button but I am not sure how to do that...
on (release)
{
_root.gotoAndStop("2");
}
I have tried this on the main timeline as well...
container_mc.btn.onRelease = function()
{
_root.gotoAndPlay(”framelabel”);
};
I have been working on this for about six straight hours and I really need to get this figured out. I would be more than happy to upload what I have if anyone would like to take a look at it. Just let me know what files you would need.
I would greatly appreciate any help with this.
Thank you...
RossKidd
March 30th, 2009, 04:46 AM
This could be a number of things. Post your .fla (you may need to zip it).
ballerz4life
March 30th, 2009, 05:45 AM
I had to upload my fla. file to Rapidshare because it was to big I guess. I hope you don't mind downloading it from there.
http://rapidshare.com/files/215256808/MDM_site_with_logo.rar.html
I really appreciate you taking a look at this for me. This is only the second website I have built and I am still trying to learn the ropes.
Thanks again...
Gnoll
March 30th, 2009, 06:00 AM
Haven't downloaded the fla but i'm guessing you arent using the labels "1", "2" for your frames, take away the quotes.. eg. gotoAndStop(1)
Gnoll
ballerz4life
March 30th, 2009, 06:36 AM
Hey Gnoll...thanks for the reply. 1,2,3 and 4 are my labels...not my frames. I have 4 samples of my work that is why they are numbered and named that way.
Thanks
Gnoll
March 30th, 2009, 07:12 AM
Wait inside of a movieclip? so you want something like mc.example1_btn.addEventListener(MouseEvent.CLICK, onExmp1Click);
ballerz4life
March 30th, 2009, 07:18 AM
I tried that as well Gnoll. I am very new to this so as RossKidd mentioned, it could be a number of things.
Hopefully, I can get someone to take a look and get me back on track.
Thanks
RossKidd
March 30th, 2009, 10:06 AM
I had a look, you are targeting movieclips that buried 3 movieclips down so you need to use
content_mc.portfoloe.example1_btn.addEventListener (MouseEvent.CLICK, yourFunction);
I think you need to make a decision, Actionscript 3 is all about object oriented programming if you are serious about learning it then go for it but if you are going to be working on mainly on the timeline then you may want to try AS2. The benefit with AS2 is you can add eventlisteners (CLICK, ROLL OVER etc) to the actual button directly and it is slightly easier to use.
MurtenSaerbi
March 30th, 2009, 12:10 PM
Your code doesn't know what to stop. Add "e.currentTarget" in front of the gotoAndStop actions.
example1_btn.addEventListener(MouseEvent.CLICK, onExmp1Click);
private function onExmp1Click(e:MouseEvent):void
{
e.currentTarget.gotoAndStop("1")
}
Gnoll
March 30th, 2009, 04:48 PM
Then he would be stopping the button :), he is just doing gotoAndStop on the main stage timeline
Gnoll
ballerz4life
March 30th, 2009, 05:40 PM
Hey guys,
Thanks for your input. I am just learning Flash and Actionscript so that is why I am having some problems. I did get a tutorial for ActionScript 3.0 in Flash CS4. I am slowly learning.
RossKidd...I did try what you mentioned before I posted my question and I could not get it to work. I will give it another go and see if I can figure it out.
Thanks again...
ballerz4life
March 30th, 2009, 06:56 PM
OK...I tried this and still a no go.
content_mc.portfolio_mc.example1_btn.addEventListe ner(MouseEvent.CLICK, onExmp1Click);
function onExmp1Click(event:MouseEvent):void
{
content_mc.gotoAndPlay("2")
}
I think I am starting to understand a little better but I just can't get it to work.
Thanks...
snickelfritz
March 30th, 2009, 07:11 PM
Interesting phenomenon: using "1" "2" "3" "4" as frame labels, sends the playhead to frames 1 2 3 4.
Changing the frame labels to "A" "B" "C" "D", sends the playhead to the frame labels.
I'm sure there's a simple explanation for this.
FLA setup for the following script: four movieclips used as buttons: example1_btn, example2_btn, example3_btn, example4_btn.
These movieclips are nested nested within a movieclip on the stage with instance name of "mc".
Main timeline has frame labels: "A" "B" "C" "D".
stop();
var frameLabels:Array =
[
"A",
"B",
"C",
"D"
];
var frameLabel:String;
for(var i:Number = 0; i < frameLabels.length; i++)
{
mc["example" + (i+1) + "_btn"].addEventListener(MouseEvent.CLICK, onExampleClick, false, 0, true);
mc["example" + (i+1) + "_btn"].buttonMode = true;
mc["example" + (i+1) + "_btn"].id = i;
}
function onExampleClick(e:MouseEvent):void
{
frameLabel = String(frameLabels[e.target.id]);
gotoAndStop(frameLabel);
}
ballerz4life
March 30th, 2009, 09:34 PM
Snickelfritz...thanks for your input. I really don't understand your code, sorry I am a newbie. I have changed the labels to A,B,C,D. So should I put this code under my other button code that is working on the main timeline?
Again...I really appreciate all the help I am getting.
Thanks
OK...I guess I did it wrong. Here is what I have:
stop();
var frameLabels:Array =
[
"A",
"B",
"C",
"D"
];
var frameLabel:String;
for(var i:Number = 0; i < frameLabels.length; i++)
{
content_mc["example" + (i+1) + "_btn"].addEventListener(MouseEvent.CLICK, onExample1Click, false, 0, true);
content_mc["example" + (i+1) + "_btn"].buttonMode = true;
content_mc["example" + (i+1) + "_btn"].id = i;
}
function onExample1Click(e:MouseEvent):void
{
frameLabel = String(frameLabels[e.target.id]);
gotoAndStop("B");
}
I added this code to the main timeline under my code for the buttons that are working.
It is not working and now I get in the output box "ypeError: Error #1009: Cannot access a property or method of a null object reference.
at MDMsitewithlogo_fla::MainTimeline/frame1()".
This is getting very frustrating...
ballerz4life
March 31st, 2009, 09:19 AM
OK Mates...this is where I am at. I am still stuck on the same problem but I have learned a few things along the way and I went ahead a finished the rest of my site instead of just sitting on my hands.
Now...if someone could take a look at my code and help me with this one simple issue I would be very grateful.
Here is the new link for the updated fla.
http://rapidshare.com/files/215731669/MDM_site_with_logo_3_pic_buttons.fla.html
I also have uploaded my site here if you want to take a look at it and give me some feedback. The problem is on the portfolio page, I just want to click on smaller pics and have them replace the bigger one.
www.massivedynamicsmarketing.com
Again, I really appreciate your help. Thank you.
Powered by vBulletin® Version 4.1.10 Copyright © 2012 vBulletin Solutions, Inc. All rights reserved.