Creative COW SIGN IN :: SPONSORS :: ADVERTISING :: ABOUT US :: CONTACT US :: FAQ
Creative COW's LinkedIn GroupCreative COW's Facebook PageCreative COW on TwitterCreative COW's Google+ PageCreative COW on YouTube
ADOBE FLASH:HomeFlash ForumFlash TutorialsFlash Video TutorialsWeb Streaming ForumAdobe FlashPodcast

One Button Add and Remove Symbol From Stage AS3

COW Forums : Adobe Flash

<< PREVIOUS   •   FAQ   •   VIEW ALL   •   PRINT   •   NEXT >>
Share on Facebook
Jay MasOne Button Add and Remove Symbol From Stage AS3
by on Dec 2, 2009 at 10:10:22 pm

Just want to know the basic code to add a symbol to the stage from the libray and to remove the symbol from the stage with one button.

Basically for example I have one button on the stage and one symbol in the library and I want to bring out the symbol to the stage with a click and then with another click remove the symbol from the stage and if I were to click it again it would bring the symbol back out ect ect.

Is there a small code block in AS3 for this?


Return to posts index
Reply   Like  

demetri tashieRe: One Button Add and Remove Symbol From Stage AS3
by on Dec 2, 2009 at 10:45:20 pm

as long as that symbol has a linkage identifier, it is quite easy. if it does not have a linkage identifier, then in the Library, select the symbol, and either click on the "i"(information) button on the bottom, or right click to get the Symbol Properties dialog box. click Linkage: Export for Actionscript, and the Class name should automaticlaly fill in . hit OK, then OK again when the warning box appears. now you use this linkage name to add the symbol to the stage/Display List

in your button function write this { addChild(symbolLInkageClassName) }

give it X and Y values to positionit if necessary.

use removeChild(symbolLInkageClassName) to remove it.


if what i think you are also asking is to use the same button to add it , then remove it -
there are several approaches to do this. one is to have the first function also remove its EventListener, and then add a new listener with the function of removing the symbol ( this function would then likewise also remove its listener, and restore the original listener)

other ways involve declaring a Boolean value and using a conditinal statement to track it.






Return to posts index
Reply   Like  

Marcus GeduldRe: One Button Add and Remove Symbol From Stage AS3
by on Dec 3, 2009 at 12:15:32 am

If I'm reading that right, it's close but not exactly right.

To bring an instance of a Library Symbol to the stage, you first have to check its Export for Actionscript option, as Demetri described above.

In your code, you create a variable to hold the instance:

var myStar : Star = new Star();

I'm assuming your Library Symbol is called Star. myStar will be the name of the instance I'm about to add to the stage.

Then, to add it to the stage, you type this:

addChild( myStar );

In your button handler, you write...

removeChild( myStar );

Author "After Effects Expressions"
Co-author "After Effects For Flash, Flash For After Effects"
Artistic Director, Folding Chair Classical Theatre, Inc
Senior Flash Developer, Zeitbyte.com


Return to posts index
Reply   Like  


Lisa PawsonRe: One Button Add and Remove Symbol From Stage AS3
by on Mar 1, 2010 at 10:04:40 am

Hi,

I am having trouble with removeChild, I have added my classes in my FLA file and in the classes it opens a swf file over the original, when this happens I need to remove my classes because some of the components are still left on stage, how could I do this? I have been struggling with this for weeks?

Thanks,
Lisa


Return to posts index
Reply   Like  

<< PREVIOUS   •   VIEW ALL   •   PRINT   •   NEXT >>
Share on Facebook


FORUMSTUTORIALSFEATURESVIDEOSPODCASTSEVENTSSERVICESNEWSLETTERNEWSBLOGS

Creative COW LinkedIn Group Creative COW Facebook Page Creative COW on Twitter
© 2014 CreativeCOW.net All rights are reserved. - Privacy Policy

[Top]