• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 2356
  • Last Modified:

AS3: How do I use button movieclips to load/unload other movieclips on stage?

Hi there experts!

I'm a newbie to AS3 and have limited experience in AS2. I'm having a tough time figuring out how to load/unload or addChild/removeChild movie clips dynamically on the main stage using AS3. The numerous tutorials I've come across on google seem to be using external .swf files when load/unloading and I've been able to get addChild/removeChild to work but can't figure out how to unload the previous movieClip before loading a new one. I apologize for the winded explaination.

I need some guidance on the best way to do this and how to make all this work in AS3. Here's what I've managed to create and have in my library.. please note, that I DO NOT have any movie clips on my stage and all instances (except the button movie clips) were set through the linkage property...

nav_mc (global navigation/instance name: nav) which contains:
  - home_mc (home pg/instance name: home)
  - about_mc (about pg/instance name: about)
  - sc_mc (services pg/instance name: sc)
  - mission_mc(mission pg/instance name: mission)

and a movie clip for each section of the site ....

homePg_mc
aboutPg_mc
scPg_mc
missionPg_mc

and because of this I have one keyframe on my main timeline with the following script. Now, how do i tell my buttons in nav_mc to unload or removeChild from the main stage before loading the new movie clip?


Any help or guidance would be greatly appreciated!!

Thanks,
SK

 
stop();
 
	var navigation:nav = new nav();
	var missionPg:mission = new mission();
	missionPg.x = 340;
	missionPg.y = 247;
	addChild(missionPg);
	navigation.x = 329;
	navigation.y = 158;
	addChild(navigation);

Open in new window

0
sk1922
Asked:
sk1922
  • 12
  • 11
1 Solution
 
Eaddy BarnesITCommented:

i am not sure if i have everything straight in my mind as to what your asking.
 
 But from what i gathered your trying to load Movie clips which have been exported for action script to the stage.
 
 what i would advise you to do is add all Movie clips to the stage. and then alternate the visible status of each as needed.
 
 this way the movie clips you don't need wont be visible or accessible until you set there visible status to true.
 
 please let me know if this helps.
 
 
 if possible could you upload a sample of the data file your working on so i can better understand what your trying to do better.
 
 Best of Luck
 
 GE
0
 
sk1922Author Commented:
I know.. I'm sorry, I'm having difficulty explaining the issue since I'm not flash dabbler.. and yes, I'm trying to load/unload movie clips that have been exported for AS.

I'm attaching the .fla file for you if you are willing to look at it. I also organized the library/folder structure to make it easier for you and what you will see on the first frame of the main timeline is a script that does the following:

- loads the cover page (the intro) on to the stage
- from within the cover_mc symbol it will fire off an event from the enter button
- this refers back to the parent timeline and executes the missionPg function which first removes the coverPg movieclip from the stage then moves on with loading the mission and the navigation movie clips.

I hope this will help you better understand what I'm trying to do.
test2.txt
0
 
Eaddy BarnesITCommented:
may i ask if there is any spacial reason why you don't have any instances on the stage?
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
sk1922Author Commented:
No special reason... just that in the reading I've been doing (can't remember where now since I've been reading all sorts of articles, tutorials, etc.) it stated that by using "Export for Actionscript" and I have the ability to call the movieclip by class name and that I can them from the stage/timeline and just add them to the stage through code?? I take it that's not entirely true?
0
 
sk1922Author Commented:
... I meant to say "...that I can delete them from the stage/timeline"
0
 
Eaddy BarnesITCommented:
do you mind if i restructure your layout and scripts a bit?

GE
0
 
sk1922Author Commented:
You are more than welcome to by all means.

That will actually help me in understanding how to implement a better timeline structure. I think that's also another thing I'm having a hard time understanding about AS3/Flash in general - is the layout and placement of symbols on the timeline.

I appreciate you helping me with this.
0
 
Eaddy BarnesITCommented:
have a look at this.
to be honest i am not sure if this is the concept you had in mind for you project.

i liked some of the codes yo used however some of it may no be needed for a light project.

do you have experience with PHP?

GE


loadingMC2.txt
0
 
sk1922Author Commented:
I'm glad you like some of the code I'm using... that tells me I'm doing SOMETHING right!! :)

This is only a sample that I'm working to put together so I can understand the concept. The REAL project I'll be working on involves 7-8 main movie clips that include 3 or 4 of their own nested clips.

and yes I do have some PHP experience.

   
0
 
Eaddy BarnesITCommented:
i saw the php in the way you coded your script.

action script also uses cases  .
also you can use arrays to better access and reference data

GE
0
 
sk1922Author Commented:
I see. I will keep that in mind.

Now, I'm disecting your code and structure to better understand...

I see where the code below will call up the mission movieclip if I click on the section2 button. But if I add the same code to the buttonClick3 function to access the about movieclip (about_mc), it will not remove/hide mission_mc on the stage. How do I tell my script to not overlap my new movieclip with the existing one on the stage.

So let's say basic user interaction is I click on "ENTER" which leads me to the navigation.. I click on MISSION, which takes me to the mission_mc animation, then I click on "ABOUT" and about_mc plays but it never unloads the previous clip (in this case mission_mc) from the stage . So regardless of whether I navigate from MISSION to ABOUT or ABOUT to MISSION the previous movieclip is still on the stage. How do I get it remove the previous clip from the stage dynamically?

CODE SAMPLE:
//MISSION
nav_mc.section2.addEventListener(MouseEvent.CLICK, buttonClick2);
nav_mc.section2.addEventListener(MouseEvent.MOUSE_OVER, buttonOut2);
 
//ABOUT
nav_mc.section3.addEventListener(MouseEvent.CLICK, buttonClick3);
nav_mc.section3.addEventListener(MouseEvent.MOUSE_OVER, buttonOut3);
 
//activates MISSION movieclip
function buttonClick2(e:MouseEvent):void {
	mission_mc.visible = true;
	mission_mc.gotoAndPlay(2);
	Tweener.addTween(nav_mc.section_mc, {alpha: 0, time: 10});
}
 
//activates ABOUT movieclip
function buttonClick3(e:MouseEvent):void {
	about_mc.visible = true;
	about_mc.gotoAndPlay(1);
	Tweener.addTween(nav_mc.section_mc, {alpha: 0, time: 10});
}

Open in new window

0
 
Eaddy BarnesITCommented:
you don't need to remove it from the stage. just remove it from the stage display list.
that's what the visible setting is for. whichever clip your not using set its visible settings
to false thereby making it inactive for the user and its status removed from the display list.

GE
0
 
sk1922Author Commented:
where would I apply that setting in my code?

How would I write it to tell it to remove the existing one from the stage so I don't have to hard code it for each function?

For example, if I wrote it this way, it would only look for mission_mc.. but what if the user is coming from home_mc. How would I tell it to set it to false dynamically?
//activates ABOUT movieclip
function buttonClick3(e:MouseEvent):void {
         mission_mc.visible = false;
	about_mc.visible = true;
	about_mc.gotoAndPlay(1);
	Tweener.addTween(nav_mc.section_mc, {alpha: 0, time: 10});
}

Open in new window

0
 
Eaddy BarnesITCommented:
sorry i should have been clear.


when you Click one button such as about.
you would set all other buttons to false while setting about to true.

GE

0
 
Eaddy BarnesITCommented:
disregard last post

when you Click one button such as about.
you would set all other movieClip or content to false while setting about us data to  true.

GE
0
 
sk1922Author Commented:

Wow. okay.. I thought maybe that's where addChild/removeChild might be able to help but I'm guessing not?

0
 
Eaddy BarnesITCommented:
u can use that also. if you would prefer.
they are all options. its just how you want
to get things done.

GE

0
 
Eaddy BarnesITCommented:
be sure to look at removeChildAt  and addChildAt.
these allow you to pic the order number the movie
clip is displayed on.
0
 
sk1922Author Commented:
I see. I'm sorry for all the questions... I'm just trying to wrap my head around AS. So thanks for being patient with me.

I'm assuming that the advantages of each vary depending on the size and complexity of the project.
 
0
 
sk1922Author Commented:
Outstanding. I will look into all of the great tips you've offered up through this thread.

Thank you so much for your time, guidance and assistance!! I appreciate it.

Is there a good "for beginners" resource such as a book, tutorial, etc. that you know of which helps someone understand the core fundamentals of AS3?

 
0
 
Eaddy BarnesITCommented:
i got some good info from

cost:
lynda.com
cartoonsmart.com

free
http://actionscript.org/

youtube also has a few starter videos for as3.

also if you have the cash check out amazon.com for the as3 bible.( keep in mind its not a direct learning guild it as the name suggest a guide throw as3 and all its many mysteries)
they have other good books also. read some of the reviews they can be helpful.

Best of luck

GE

P.S Good luck in AS3 its been a great time for me so far

0
 
sk1922Author Commented:
Thanks greeneel!!

I'm sure it will be equally fun and frustrating going through the process!
I will be sure to check out all of the resources.

Thanks AGAIN!!! You've been a great help!

SK
0
 
sk1922Author Commented:
I'm truly great for the help! I hope someday I can return the favor.
You went above and beyond what I was expecting!! Thanks again!!

SK
0

Featured Post

Prep for the ITIL® Foundation Certification Exam

December’s Course of the Month is now available! Enroll to learn ITIL® Foundation best practices for delivering IT services effectively and efficiently.

  • 12
  • 11
Tackle projects and never again get stuck behind a technical roadblock.
Join Now