AddChild and removeChild with MouseEvent

Hello, I am a newby at AS3. I need help with addChild and removeChild.
I want to make a two buttons one addChild and other removeChild . Friend helped me a little bit, but I didnt uderstand the script ;]
Here is the example script which my friend gave to me. In other words I want to make a button that attached hair and the other that removes.
Should I make a separete custom class for Hair? And if do, can someone help? :]
ActionScript Code:
public function changeHairs (newHair: Hair): Hair
Face.removeChild (oldHairs);
oldHairs = newHair;
Face.addChild (newHair);
newHair return;
Or modify this code. I know how to change text, but dont know how to change objects
ActionScript Code:
package  {
    import flash.display.MovieClip;
    import Button;
    import flash.text.TextField;
    import flash.events.MouseEvent;
    public class Faces2 extends MovieClip
        public var arr:Array = new Array("a1","a2","a3");
        trace("aab");
        public var txt:TextField = new TextField()
        public var btnBack:Button = new Button();
        public var btnFwd:Button = new Button();
        public var arrPos:Number = 0;
        public function Faces2()
            setupInterface();
            setupData(arrPos);
        public function setupInterface():void
            btnBack.x = 100; btnBack.y = 10;
            btnFwd.x = 200; btnFwd.y = 10;
            btnBack.addEventListener(MouseEvent.CLICK, back);
            btnFwd.addEventListener(MouseEvent.CLICK, fwd);
            addChild(btnBack);
            addChild(btnFwd);
            txt.textColor = 0xFF0000;
            txt.width = 300;
            txt.border = true;
            txt.x = 100; txt.y = 100;
            addChild(txt)
        public function fwd(evt:MouseEvent):void
            arrPos ++;
            if(arrPos >= arr.length)
                arrPos = 0;
            setupData(arrPos);
        public function back(evt:MouseEvent):void
            arrPos --;
            if(arrPos < 0)
                arrPos = arr.length - 1;
            setupData(arrPos);
        public function setupData(pos:Number):void
            txt.text = arr[pos];
P.S. sorry for my bad english

did you create your hair movieclip and assign it a class?

Similar Messages

  • Action script 3 question: addChild and removeChild on same button??

    I'm trying to make a button that when u click once, the movieclip will be removed and second time back on stage and so forth....
    somehow i get this error
    ==================================
    ArgumentError: Error #2025: The supplied DisplayObject must be a child of the caller.
    at flash.display:DisplayObjectContainer/removeChild()
    at sample_fla::MainTimeline/btnClick()
    ==================================
    Anyone can help me with this, since I'm doing an interactive web for client and the deadline is near..... thanks in advance.
    these are my code:
    stop();
    var swf:MovieClip;
    var loader:Loader= new Loader();
    var defaultswf:URLRequest= new URLRequest("./newSwfImport.swf");
    //default swf when loaded
    loader.load(defaultswf);
    //add to stage
    allSwfLoadHere.addChild(loader);
    var boolean:Boolean = true ;
    function btnClick(event:MouseEvent):void {
    if(boolean == true){
    allSwfLoadHere.removeChild(loader);
    boolean == false
    if(boolean ==false){
    allSwfLoadHere.addChild(loader);
    boolean == true
    newSwfImport.addEventListener(MouseEvent.CLICK,btnClick);

    you have, at least, two errors:
    1.  you failed to use an if-else and
    2.  when trying to re-assign your boolean, you tested.  ie, you used == when you should use =.  so, your boolean remains true.  then when you execute the 2nd time, you try and remove something that's already been removed.
    use:
    var swf:MovieClip;
    var loader:Loader= new Loader();
    var defaultswf:URLRequest= new URLRequest("./newSwfImport.swf");
    //default swf when loaded
    loader.load(defaultswf);
    //add to stage
    allSwfLoadHere.addChild(loader);
    var boolean:Boolean = true ;
    function btnClick(event:MouseEvent):void {
    if(boolean){
    allSwfLoadHere.removeChild(loader);
    } else {
    allSwfLoadHere.addChild(loader);
    boolean=!boolean;
    newSwfImport.addEventListener(MouseEvent.CLICK,btnClick);

  • Explanation of addChild and removeChild?

    Hi
    I'm having trouble getting my head around using removeChild.
    For example, I have a function that is triggered by a button click.  This function loads an external swf.  I then set a global variable swfLoaded to true, with the idea of having an if condition that executes removeChild(loader) if swfLoaded is true.
    When trying to execute removeChild(loader), I get an error telling me that it must be the child of the caller.
    I've seen the code below, which loads a default swf, but I don't want a default swf - I just want one loaded if the button is clicked, and then if another button is clicked, the original one to be removed before the next swf is loaded.
    Can someone please explain to me why removeChild(loader) only works if addChild(loader) was originally executed outside of the function (like below)?
    How do I make this code work without loading a default swf, just loading one once someone clicks a button, and then removing it?
    var Xpos:Number = 110;
    var Ypos:Number = 180;
    var swf:MovieClip;
    var loader:Loader = new Loader();
    var defaultSWF:URLRequest = new URLRequest("swfs/eyesClosed.swf");
    loader.load(defaultSWF);
    loader.x = Xpos;
    loader.y = Ypos;
    addChild(loader);
    // Btns Universal function
    function btnClick(event:MouseEvent):void {
    removeChild(loader);
    var newSWFRequest:URLRequest = new URLRequest("swfs/" + event.target.name + ".swf");
    loader.load(newSWFRequest);
    loader.x = Xpos;
    loader.y = Ypos;
    addChild(loader);
    // Btn listeners
    eyesClosed.addEventListener(MouseEvent.CLICK, btnClick);
    stingray.addEventListener(MouseEvent.CLICK, btnClick);
    demon.addEventListener(MouseEvent.CLICK, btnClick);
    strongman.addEventListener(MouseEvent.CLICK, btnClick);
    Cheers
    Shaun

    Oh, I just did not pay enough attention to your code.
    The way you wrote it - you don' have to remove it every time. A better approach is to add it only once and in subsequent calls to unload it:
    var loader:Loader = new Loader();
    // add it once
    addChild(loader);
    function btnClick(event:MouseEvent):void {
         // don't need this
         //removeChild(loader);
         // unload previously loaded content
         loader.unload();
         var newSWFRequest:URLRequest = new URLRequest("swfs/" + event.target.name + ".swf");
         loader.load(newSWFRequest);
         loader.x = Xpos;
         loader.y = Ypos;
         // don't need this either
         // addChild(loader);
    Also, in Flash 10 it is better to use loader.unloadAndStop()

  • Loading .swf, addChild, and removeChild

    Hello all,
    I'm trying load an swf when you click a button, and load another in it's place when you click a different button.   I'm using addChild to insert the swf onto the stage.  Problem is that every time I click a new button, the new swf is loaded on top of the previous one, and I need the previous one to disappear.  I tried using the removeChild method before the new swf is loaded to no effect.
    Here's the function I'm using for the loader with my removeChild attempt in bold:
    function newPage():void {
        trace("load activated");
        trace(""+target+".swf");
        var req:URLRequest=new URLRequest(""+target+""+".swf");
        var loader:Loader = new Loader();
       if (loaderState==true){
            top_mc.removeChild(loader);
        loader.load(req);
        loader.contentLoaderInfo.addEventListener(ProgressEvent.PROGRESS, preLoad);
        loader.contentLoaderInfo.addEventListener(Event.COMPLETE, fileLoaded);
        function preLoad(event:ProgressEvent):void {
            var percent:Number=Math.round(event.bytesLoaded/event.bytesTotal*100);
            top_mc.preload_txt.text=String(""+percent+"");
        function fileLoaded(event:Event):void {
            trace("file loaded");
            top_mc.addChild(loader);
            loaderState=true;
    The error I get is as follows:
    ArgumentError: Error #2025: The supplied DisplayObject must be a child of the caller.
        at flash.display::DisplayObjectContainer/removeChild()
        at main_fla::MainTimeline/newPage()
        at main_fla::MainTimeline/workLoaderEnter()
        at main_fla::MainTimeline/clickF()
    Perhaps there is a way to give the addChild an instance name so that I can remove it later?
    Any ideas?
    Thanks!

    Part of the problem is your trying to remove the loader just after you define it...  it is not a child of anything at that point.  Try the following instead of what you have.   Another problem you can avoid is to not nest functions...
    var loader:Loader
    var loaderState:Boolean = false;
    function newPage():void {
    if (loaderState){
            top_mc.removeChild(loader);
        var req:URLRequest=new URLRequest(""+target+""+".swf");
        loader = new Loader();
        loader.load(req);
        loader.contentLoaderInfo.addEventListener(ProgressEvent.PROGRESS, preLoad);
        loader.contentLoaderInfo.addEventListener(Event.COMPLETE, fileLoaded);
    function preLoad(event:ProgressEvent):void {
        var percent:Number=Math.round(event.bytesLoaded/event.bytesTotal*100);
        top_mc.preload_txt.text=String(""+percent+"");
    function fileLoaded(event:Event):void {
        top_mc.addChild(loader);
        loaderState=true;

  • AddChild and removeChild (AS 3)

    Hi
    If I load an external swf (located in the same dir as the one
    loading it) with addChild. It looks something like this
    var url:String = "patfinder_extra1.swf";
    var urlReq:URLRequest = new URLRequest(url);
    ldr.load(urlReq);
    addChild(ldr);
    Now, I want to be able to close/remove this new child within
    itself, image a little close button with the label "I'm a child and
    will close my self if i click here!".
    Now, this removeChild is a mystery and the new restrictions
    in paths in AS 3 really makes it hard. To simply use
    this.removeChild() returns errors.
    Any tips of how to close this thingy?
    :)

    you can use the code below to have the child movieclip remove
    itself from its parent's display list, but that won't clear it for
    garbage collection.
    i would have the child call a function in the parent that
    removes it and nulls all references to its loader so it can be
    garage collected.

  • Cannot click and drag with bluetooth mouse?

    I have installed bluetooth mouse and works fine but cannot click and drag using the mouse in any applications. will highlight stuff and cursor moves fine but then cannot drag using the mouse. Any ideas?

    I was trying with this code which I got from this website as I am beginner of AS3.
    var images:MovieClip = images_mc;
    var offsetFrame:int = images.currentFrame;
    var offsetX:Number = 0;
    var offsetY:Number = 0;
    var percent:Number = 0;
    images.addEventListener(MouseEvent.MOUSE_DOWN,startDragging);
    images.addEventListener(MouseEvent.MOUSE_UP,stopDragging);
    function startDragging(e:MouseEvent):void
    images.addEventListener(MouseEvent.MOUSE_MOVE,drag);
    offsetX = e.stageX;
    offsetY = e.stageY;
    function stopDragging(e:MouseEvent):void
    images.removeEventListener(MouseEvent.MOUSE_MOVE,drag);
    offsetFrame = images.currentFrame;
    function drag(e:MouseEvent):void
    percent =  (e.stageX - offsetX)/images.width;
    percent =  (e.stageY - offsetY)/images.height;
    var frame:int = Math.round(percent*images.totalFrames) + offsetFrame +1;
    while (frame>images.totalFrames)
      frame -=  images.totalFrames;
    while (frame<=0)
      frame +=  images.totalFrames;
    images.gotoAndStop(frame);
    This has to rotate in top also i.e., I also have images sequence placed with top view also.
    If I use keyboard, it has to work with arrow keys also and also with mouse interactivity.

  • How do I use Qt and OpenGL with Visual Studio

    Hi! I mainly want to program in C++ and I want to use Qt and OpenGL with Visual Studio.
    I am currently revising C++ and later on i am going to start reading Qt and OpenGL. I have a background of
    Embedded firmware design(C and Assembly).
    The Visual Studio Version I have is 2013 ultimate. How do I use Qt and OpenGL with Visual Studio?
    Thanks
    Alexandros

    Hi ClassicalGuitar,
    The forum supports VS setup and installation. And your issue is not about the forum. I will move the thread to off-topic forum. Thanks for your understanding.
    Regards,
    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

  • Open report with "Save as" and "Open with" dialogue

    Hi,
    I'm using jasper reports within my application. I manage to open them in a new window but in that case the url containing JasperServer username and password is shown. I would like to open the report without showing the url.
    I tryed using a database procedure (http://sqlcur.blogspot.com/2009/02/jasperreports-in-apex.html) but all I get is a alert window saying "file does not begin with ' pdf-'". Couldn't see what is the problem (I used the same procedure as Ino has in his example) so I thought of another way. Is it possible, when someone clicks a button to open a report, to open that report with a "Save as" and "Open with" pop up window?
    The javascript function that I use:
    <script language="JavaScript" type="text/javascript">
    function openLAPopUpJasper(url){
    w = open(url,"winLov","toolbar=false,menubar=false,location=false,resizable=yes, //scrollbars=yes,status=yes,fullscreen=true");
    if (w.opener == null)
    w.opener = self;
    w.focus();
    </script>
    Thanks in advance!
    Edited by: Josip on Oct 29, 2009 2:55 AM

    Anyone?

  • Troubleshoting help needed:  My iMac keeps crashing and restarting with a report detail: "spinlock application timed out"  What can I do to fix this?timed out"

    Troubleshooting help needed:  My iMac keeps crashing and restarting with a notice: "Spinlock application timed out"  What can I do?

    Launch the Console application in any of the following ways:
    ☞ Enter the first few letters of its name into a Spotlight search. Select it in the results (it should be at the top.)
    ☞ In the Finder, select Go ▹ Utilities from the menu bar, or press the key combination shift-command-U. The application is in the folder that opens.
    ☞ Open LaunchPad. Click Utilities, then Console in the page that opens.
    Select the most recent panic log under System Diagnostic Reports. Post the contents — the text, please, not a screenshot. In the interest of privacy, I suggest you edit out the “Anonymous UUID,” a long string of letters, numbers, and dashes in the header and body of the report, if it’s present (it may not be.) Please don't post shutdownStall, spin, or hang reports.

  • Is there a way to create a PDF form that ANYONE can fill out and SAVE with their content?

    Is there a way to create a PDF form that ANYONE can fill out and SAVE with their content? By anyone, I mean someone who can download and use the free Adobe Reader, on either a Mac or PC. I have Acrobat Pro, and would like to be able to create forms that can not only be filled out and printed, but saved and emailed, which is not an option with the forms I have created to date. They can be filled out, but not saved, with Adobe Reader.
    TIA,
    Nancy

    To do what Dave indicated you need to do, it depends on what version of Acrobat you have:
    Acrobat 8: Advanced > Enable Usage Rights in Adobe Reader
    Acrobat 9: Advanced > Extend Features in Adobe Reader
    Acrobat 10: File > Save As > Reader Extended PDF > Enable Additional Features
    Acrobat 11: File > Save as Other > Reader Extended PDF > Enable More Tools (includes form fill-in & save)
    I wonder what it will be next time?

  • My Outlook/iCloud calendar invites to others appear to work on my end and sync with my PC and mobile, but when other people "accept" the invite, it will not populate/add in to their calendar. How can i fix this without turning off iCloud?

    My Outlook/iCloud calendar invites to others appear to work on my end and sync with my PC and mobile, but when other people "accept" the invite, it will not populate/add in to their calendar. How can I fix this without turning off iCloud?
    I am at a new office that uses Outlook (not Outlook Exchange) which does not sync with my mobile... I just got iCloud set up on my PC to sync my contacts, calendar, reminders, etc... The sync worked (not without flaws, but the other issues seem solvable... I think), so that i can now see all my appointments on both my phone and on my PC. The problem I am having is that iCloud moved all of my calendar items from Outlook into iCloud calendar and now when I send out meeting/calendar invites the recipients may accept them, but the meeting does not get added to their calendar. This is a huge problem and may mean that i need to turn off iCloud.
    Does anyone know how to fix this?
    Thanks!

    I am replying to my own post here as I seem to have fixed the problem.
    I do have some calendars that are shared. Some of those are shared with users who have time zone support turned on. So i activated time zone support on my iphone, then deleted my icloud subscription. I then signed in to icloud again and voila... problem solved.
    It is a weird one as the other calendar views were always fine and when you opened an event that appeared in the wrong day (on list view), the correct date of the event was shown in the information...
    one more bug in a complicated system I guess

  • My ipod nano is no longer recognized by itunes after I installed windows 8.1.  The ipod nano still is recognized and works with a Windows 7 computer

    My ipod nano is no longer recognized by itunes after I installed windows 8.1.  The ipod nano still is recognized and works with a Windows 7 computer

    Hello, Pete. 
    Here is an article I would recommend going through when an iPod is not recognized by iTunes or the computer.
    iPod not recognized in My Computer and in iTunes for Windows
    http://support.apple.com/kb/ts1369
    Usually the resolution is updating the Apple Mobile Device Driver.  See the section labeled Verify that the Apple Mobile Device USB Driver is installed > For Windows Vista, Windows 7, and Windows 8 > Update the Apple Mobile Device Driver.
    iOS: Device not recognized in iTunes for Windows
    http://support.apple.com/kb/TS1538
    Cheers,
    Jason H. 

  • All my purchased song from iTunes are not playing complete (iPod and computer with Windows Vista), unexpectedly stops and continues with next song. What am I doing wrong?

    All my purchased song from iTunes are not playing complete (iPod and computer with Windows Vista), unexpectedly stops and continues with next song. What am I doing wrong?

    Are the songs playing whole in iTunes? if not download them again.
    else read this Apple Support Article on your problem
    Have a nice day!

  • MY system folder, including hidden folders are littered with duplicate folders and files with the suffix (from old Mac) How do I remove them

    I have a Macbook Pro running Leopard 10.5.8. I had a problem with my my operating system (my fault, I moved a file I shoudnt have) couldnt boot up but was able to boot up from a backup. I managed to repair my original system except now all the system folders, including hidden folders are littered with duplicate folders and files with the suffix (from old Mac).  For the most part the dupes are an exact copy, but not always.  I want to remove them to free up space and cant imagine duplicate folders in the /system/library are not hindering my computer. But I dont know where to start and am afraid of doing irreparable damage. Any ideas

    pacull,
    Use iCal>View>Show Notifications to choose what to do with the notification.

  • How can we get Dynamic columns and data with RTF Templates in BI Publisher

    How can we get Dynamic columns and data with RTf Templates.
    My requirement is :
    create table xxinv_item_pei_taginfo(item_id number,
    Organization_id number,
    item varchar2(4000),
    record_type varchar2(4000),
    record_value CLOB,
    State varchar2(4000));
    insert into xxinv_item_pei_taginfo values( 493991 ,224, '1265-D30', 'USES','fever','TX');
    insert into xxinv_item_pei_taginfo values( 493991 ,224, '1265-D30', 'HOW TO USE','one tablet daily','TX');
    insert into xxinv_item_pei_taginfo values( 493991 ,224, '1265-D30', 'SIDE EFFECTS','XYZ','TX');
    insert into xxinv_item_pei_taginfo values( 493991 ,224, '1265-D30', 'DRUG INTERACTION','ABC','TX');
    insert into xxinv_item_pei_taginfo values( 493991 ,224, '1265-D30', 'OVERDOSE','Go and see doctor','TX');
    insert into xxinv_item_pei_taginfo values( 493991 ,224, '1265-D30', 'NOTES','Take after meal','TX');
    select * from xxinv_item_pei_taginfo;
    Item id Org Id Item Record_type Record_value State
    493991     224     1265-D30     USES     fever     TX
    493991     224     1265-D30     HOW TO USE     one tablet daily     TX
    493991     224     1265-D30     SIDE EFFECTS     XYZ     TX
    493991     224     1265-D30     DRUG INTERACTION     ABC     TX
    493991     224     1265-D30     OVERDOSE      Go and see doctor     TX
    493991     224     1265-D30     NOTES     Take after meal     TX
    Above is my data
    I have to fetch the record_type from a lookup where I can have any of the record type, sometime USES, HOW TO USE, SIDE EFFECTS and sometimes some other set of record types
    In my report I have to get these record typpes as field name dynamically whichever is available in that lookup and record values against them.
    its a BI Publisher report.
    please suggest

    if you have data in db then you can create xml with needed structure
    and so you can create bip report
    do you have errors or .... ?

Maybe you are looking for

  • Visibility of non-SAP reports and documents in the Portal

    Hi All, I am new to the portal forum and need your direction.  We have the need for outside users to view static reports and documents not generated by SAP on the portal.  Can anyone point me to documentation on how this can be accomplished? We do no

  • SAP best practice on scheduling agreements

    Hello all, Our client is an automotive supplier and currently in the SAP environment we use spot POs for indirect purchasing (thru SRM) and scheduling agreement for direct procurement. The scheduling agreements have multiple lines and we try to proce

  • Instruments: Average CPU Load over one minute

    Hi everyone. I've written some compositions in Quartz Composer and want to demonstrate how they tax the CPU in various conditions. I've opened up Instruments and I can get it to give me a readout for the individual process (Quartz Composer) but I can

  • Add a help bubble at Home, Next & Previous buttons

    Hi, Can we add balloon help on 'Home', 'Next' and 'Previous' buttons? Thanks in advance.

  • I get a error message: All downloads loads and file copies have been paused

    I have been trying to download the new 4 upgrade and I been getting this message: All downloads and file copies have been paused. The disk you are attempting to use is full. Remove files and emptying the Recycle Bin will free up additional space. Ok