Attach Movieclip and delete it
A Flash Developer Resource Site

Results 1 to 16 of 16

Thread: Attach Movieclip and delete it

  1. #1
    Is the best Alloy Bacon's Avatar
    Join Date
    Apr 2011
    Posts
    395

    Attach Movieclip and delete it

    How can I click anywhere on stage to attach a movieclip to the x and y coords of the mouse, Thanks
    https://www.paypal.com/cgi-bin/websc...if%3aNonHosted <--- Please donate if I solved your problem

  2. #2
    . fruitbeard's Avatar
    Join Date
    Oct 2011
    Posts
    1,051
    Hi,

    This should get you started, with a new *.fla, create a moveiclip and give linkage name of newClip, do not put it on the stage.

    and in the same fla use this code
    PHP Code:
    import flash.display.MovieClip;
    import flash.events.MouseEvent;

    var 
    addedClip:MovieClip;

    stage.addEventListener(MouseEvent.MOUSE_DOWNaddClip,false,0,true);
    function 
    addClip(e:MouseEvent):void
    {
        
    trace("Clicked");
        
    addedClip = new newClip();
        
    addedClip.stage.mouseX;
        
    addedClip.stage.mouseY;
        
    addChild(addedClip);


  3. #3
    . fruitbeard's Avatar
    Join Date
    Oct 2011
    Posts
    1,051
    Hi,

    I think you said something about removing it too, so.

    ideally, you would put the new clips inside another clip on the stage rather than adding them to the stage directly.
    PHP Code:
    import flash.display.MovieClip;
    import flash.events.MouseEvent;

    var 
    addedClip:MovieClip;
    var 
    containerClip:MovieClip = new MovieClip();

    stage.addEventListener(MouseEvent.CLICKaddClip,false,0,true);

    addChild(containerClip);

    function 
    addClip(e:MouseEvent):void
    {
        
    trace("Stage clicked");

        
    addedClip = new newClip();
        
    containerClip.addChild(addedClip);
        
    with (addedClip)
        {
            
    stage.mouseX;
            
    stage.mouseY;
            
    addEventListener(MouseEvent.MOUSE_DOWN,removeMe,false,0,true);
        }
    }

    function 
    removeMe(e:MouseEvent):void
    {
        
    trace("Removed me");
        
    e.currentTarget.removeEventListener(MouseEvent.MOUSE_DOWN,removeMe);
        
    e.currentTarget.parent.removeChild(e.currentTarget);

    Last edited by fruitbeard; 07-11-2014 at 01:18 PM.

  4. #4
    Is the best Alloy Bacon's Avatar
    Join Date
    Apr 2011
    Posts
    395
    Thanks, Check your paypal can you comment the code though, trying to actually learn as3 since I guess im moving up here and abandoning as2
    Last edited by Alloy Bacon; 07-11-2014 at 01:30 PM.
    https://www.paypal.com/cgi-bin/websc...if%3aNonHosted <--- Please donate if I solved your problem

  5. #5
    . fruitbeard's Avatar
    Join Date
    Oct 2011
    Posts
    1,051
    And if you get truly stuck, here is the fla, CS5

    Thanks for the donation Alloy, I shall spend it wisely.
    Attached Files Attached Files

  6. #6
    . fruitbeard's Avatar
    Join Date
    Oct 2011
    Posts
    1,051
    can do later alloy if somebody else doesn't, about to eat now...

  7. #7
    Is the best Alloy Bacon's Avatar
    Join Date
    Apr 2011
    Posts
    395
    Its cool, ill figure it out
    https://www.paypal.com/cgi-bin/websc...if%3aNonHosted <--- Please donate if I solved your problem

  8. #8
    Is the best Alloy Bacon's Avatar
    Join Date
    Apr 2011
    Posts
    395
    How can I change that removeme listener to be a hitest, im trying to get gravity to work on the movieclips so they fall down as you click, and they will hit some other movieclip under em to delete them
    https://www.paypal.com/cgi-bin/websc...if%3aNonHosted <--- Please donate if I solved your problem

  9. #9
    . fruitbeard's Avatar
    Join Date
    Oct 2011
    Posts
    1,051
    Hi,

    Quickly though Alloy as the girlfriend wants to watch movie together, something like so
    PHP Code:
    import flash.display.MovieClip;
    import flash.events.MouseEvent;

    var 
    addedClip:MovieClip;
    var 
    containerClip:MovieClip = new MovieClip();

    stage.addEventListener(MouseEvent.CLICKaddClip,false,0,true);

    addChild(containerClip);

    function 
    addClip(e:MouseEvent):void
    {
        
    trace("Stage clicked - clip added");

        
    addedClip = new newClip();
        
    containerClip.addChild(addedClip);
        
    with (addedClip)
        {
            
    stage.mouseX;
            
    stage.mouseY;
            
    addEventListener(Event.ENTER_FRAME,removeMe,false,0,true);
        }
    }

    function 
    removeMe(e:Event):void
    {
        
    e.currentTarget.+=  5;
        if (
    e.currentTarget.hitTestObject(someOtherMovieClip))
        {
            
    e.currentTarget.removeEventListener(Event.ENTER_FRAME,removeMe);
            
    e.currentTarget.parent.removeChild(e.currentTarget);
            
    trace("Removed me");
        }


  10. #10
    Is the best Alloy Bacon's Avatar
    Join Date
    Apr 2011
    Posts
    395
    thx
    https://www.paypal.com/cgi-bin/websc...if%3aNonHosted <--- Please donate if I solved your problem

  11. #11
    Is the best Alloy Bacon's Avatar
    Join Date
    Apr 2011
    Posts
    395
    TypeError: Error #1034: Type Coercion failed: cannot convert someOtherMovieClip$ to flash.display.DisplayObject.
    at gravitydrops_fla::MainTimeline/removeMe()

    wont remove
    https://www.paypal.com/cgi-bin/websc...if%3aNonHosted <--- Please donate if I solved your problem

  12. #12
    . fruitbeard's Avatar
    Join Date
    Oct 2011
    Posts
    1,051
    Hi,

    The error code is telling you that it is coming from the removeMe() function, obviously it wont remove it.
    you can either look up the error codes and work it out for yourself or attach your *.fla file, even a skeleton version if needed, as it works with my test example.

  13. #13
    Is the best Alloy Bacon's Avatar
    Join Date
    Apr 2011
    Posts
    395
    Try to fix it, I will fund you some more
    Attached Files Attached Files
    https://www.paypal.com/cgi-bin/websc...if%3aNonHosted <--- Please donate if I solved your problem

  14. #14
    . fruitbeard's Avatar
    Join Date
    Oct 2011
    Posts
    1,051
    Hi,

    You need to do either one of two things here.

    Firstly give the bluebox a name and remove the linkage name from the library of the bluebox.

    or

    manually remove the bluebox from the stage and attach it using code usuing the linkage name, same way as addedClip is done.

    I think most people would say try not to put things directly on the stage.

  15. #15
    Is the best Alloy Bacon's Avatar
    Join Date
    Apr 2011
    Posts
    395
    Thanks, Check your paypal
    https://www.paypal.com/cgi-bin/websc...if%3aNonHosted <--- Please donate if I solved your problem

  16. #16
    Is the best Alloy Bacon's Avatar
    Join Date
    Apr 2011
    Posts
    395
    Also if you need any art work for your projects I got you, I make really good 8bit
    https://www.paypal.com/cgi-bin/websc...if%3aNonHosted <--- Please donate if I solved your problem

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width


HTML5 Development Center

Poll by Flashkit.com