DEPAdmin
asked on
Adding a movieclip from the library and having it play when frame is entered (Flash CS5)
Hello -
I'm kind of new to Flash CS5 and AS3 (on the Mac) and need help with some coding.
I would like to enter a frame on the timeline and have a movieclip load from the library and play. The name of the movieclip is "transition_mc" and the Linkage is "Trans_1". How would I do this with AS3?
Thanks for your help.
I'm kind of new to Flash CS5 and AS3 (on the Mac) and need help with some coding.
I would like to enter a frame on the timeline and have a movieclip load from the library and play. The name of the movieclip is "transition_mc" and the Linkage is "Trans_1". How would I do this with AS3?
Thanks for your help.
ASKER
Thanks for your answer. UNFORTUNATELY my Agency is blocking me from viewing that website (sigh...). Would you be able to copy and paste the code from that site onto here?
Does any of these work for you???
http://www.dakmm.com/?p=333
http://www.datafake.com/blog/?p=4
Here is the copy from the first link in case you are not able to view it...
It says 'var dot:Dot= new Dot;' but it's missing the parenthesis, so it should be really this: 'var dot:Dot= new Dot();'
CyanBlue
http://www.dakmm.com/?p=333
http://www.datafake.com/blog/?p=4
Here is the copy from the first link in case you are not able to view it...
Create a movieClip on your stage and name it mcDot.
Delete the mcDot from your stage.
Open the library panel, right-click the mcDot clip then select properties:
Under the "Linkage" category check "Export for ActionScript"
Give the class the name "Dot". Make sure it is capitalized.
var dot:Dot= new Dot;
addChild(dot);
dot.x=stage.stageWidth/2;
dot.y=stage.stageHeight/2;
It says 'var dot:Dot= new Dot;' but it's missing the parenthesis, so it should be really this: 'var dot:Dot= new Dot();'
CyanBlue
ASKER
Yes, the other 2 links worked, thanks.
OK so now I figured out how to properly create a movieclip and add it to the stage when you enter a frame. However, I want it to be removed from the stage when you exit that frame. For example, I have a top navigation bar that is visible throughout my entire project. It contains a few buttons (one of which is "home"). If I click on "home" to return to the homepage, the movieclip should be removed from the stage and disappear (until that certain frame is entered again later on where it would reappear). How would this be possible?
OK so now I figured out how to properly create a movieclip and add it to the stage when you enter a frame. However, I want it to be removed from the stage when you exit that frame. For example, I have a top navigation bar that is visible throughout my entire project. It contains a few buttons (one of which is "home"). If I click on "home" to return to the homepage, the movieclip should be removed from the stage and disappear (until that certain frame is entered again later on where it would reappear). How would this be possible?
Just use removeChild() method as in removeChild(dot) in the above example whenever you need to remove it...
CyanBlue
CyanBlue
ASKER
I have A LOT of frames (over 1,000) in this project. I'm not entirely sure where to insert the "removeChild" code. Ideally I just want the movieclip to be removed when you exit the frame when you click on a button in the navigation bar. Can I create some kind of "exit frame" event to execute this code? (Sorry, like I said, I'm pretty new to this lol).
Well, I wouldn't know 'when' you are exiting the frame... You could try adding that command on a CLICK event handler you have for the button and see if that works for you...
CyanBlue
CyanBlue
ASKER
Hmm...I tried to add the following code to the "home" button:
home_btn.addEventListener( MouseEvent .CLICK, homepage);
function homepage (event:MouseEvent):void
{
gotoAndPlay("home");
removeChild(s2keypoints_mc );
}
It seems to work when I exit the frame via the "home" button (no errors are displayed and the movieclip is removed), however, if I click the "home" button at any other time throughout the project on all of the other frames that do not contain the movieclip I get the following error:
ArgumentError: Error #2025: The supplied DisplayObject must be a child of the caller.
at flash.display::DisplayObje ctContaine r/removeCh ild()
at CBTSupvDisc_fla::MainTimel ine/sample memos()
The "CBTSupvDisc.fla" is the file name, and "samplememos" is the name of another button in the navigation bar.
What does this mean?
home_btn.addEventListener(
function homepage (event:MouseEvent):void
{
gotoAndPlay("home");
removeChild(s2keypoints_mc
}
It seems to work when I exit the frame via the "home" button (no errors are displayed and the movieclip is removed), however, if I click the "home" button at any other time throughout the project on all of the other frames that do not contain the movieclip I get the following error:
ArgumentError: Error #2025: The supplied DisplayObject must be a child of the caller.
at flash.display::DisplayObje
at CBTSupvDisc_fla::MainTimel
The "CBTSupvDisc.fla" is the file name, and "samplememos" is the name of another button in the navigation bar.
What does this mean?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
You are, indeed, a genius lol. Thanks so much, it works perfectly!
ASKER
HUGE help!
Glad to help... ;)
CyanBlue
CyanBlue
http://asgamer.com/2009/flash-game-design-basics-adding-library-objects-to-stage-with-as3
CyanBlue