Solved

Adding a movieclip from the library and having it play when frame is entered (Flash CS5)

Posted on 2011-03-08
12
367 Views
Last Modified: 2012-05-11
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.
0
Comment
Question by:DEPAdmin
  • 6
  • 6
12 Comments
 
LVL 37

Expert Comment

by:CyanBlue
ID: 35070433
Check out the step 2 to setup the library item and step 6 to actually add it onto the stage...  FYI, You don't have to have 'stage.' in the second command...
   http://asgamer.com/2009/flash-game-design-basics-adding-library-objects-to-stage-with-as3

CyanBlue
0
 

Author Comment

by:DEPAdmin
ID: 35070656
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?
0
 
LVL 37

Expert Comment

by:CyanBlue
ID: 35070811
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...
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;

Open in new window


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
0
 

Author Comment

by:DEPAdmin
ID: 35071304
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?
0
 
LVL 37

Expert Comment

by:CyanBlue
ID: 35071382
Just use removeChild() method as in removeChild(dot) in the above example whenever you need to remove it...  

CyanBlue
0
 

Author Comment

by:DEPAdmin
ID: 35071486
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).
0
3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

 
LVL 37

Expert Comment

by:CyanBlue
ID: 35071523
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
0
 

Author Comment

by:DEPAdmin
ID: 35073013
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::DisplayObjectContainer/removeChild()
      at CBTSupvDisc_fla::MainTimeline/samplememos()

The "CBTSupvDisc.fla" is the file name, and "samplememos" is the name of another button in the navigation bar.

What does this mean?
0
 
LVL 37

Accepted Solution

by:
CyanBlue earned 500 total points
ID: 35074000
You could try this...
function homepage (event:MouseEvent):void
{
      if (s2keypoints_mc.parent != null)
      {
            s2keypoints_mc.parent.removeChild(s2keypoints_mc);
      }
      gotoAndPlay("home");
}

Open in new window

0
 

Author Comment

by:DEPAdmin
ID: 35074105
You are, indeed, a genius lol.  Thanks so much, it works perfectly!
0
 

Author Closing Comment

by:DEPAdmin
ID: 35074113
HUGE help!
0
 
LVL 37

Expert Comment

by:CyanBlue
ID: 35074261
Glad to help...  ;)

CyanBlue
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Input past end of file vbs script 9 81
exchange 2007, scripts 15 71
Could you point how to deal with this kind of PHP notation? 7 98
view results of google SQL query 9 52
Recently, I was asked to recommend a tracking system to be implemented on a clients website. As the entire site was built on flash, my first thought was to suggest custom built tracking system. However, our company at that point of time didn't h…
It is becoming increasingly popular to have a front-page slider on a web site. Nearly every TV website,  magazine or online news has one on their site, and even some e-commerce sites have one. Today you can use sliders with Joomla, WordPress or …
The goal of the tutorial is to teach the user how to live broadcast using Flash Media Live Encoder and connecting it to YouTube to broadcast. Log into your Youtube account, choose live stream settings, start live stream from Flash Media Live Enc…
In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…

919 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now