Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7658719
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T13:14:18+00:00 2026-05-31T13:14:18+00:00

So basically I’ve got a MovieClip called Jug and when the egg is clicked

  • 0

So basically I’ve got a MovieClip called Jug and when the egg is clicked and dragged to the Jug I want it to disappear and then re-add itself in the place it first started. Aswell as this I want a variable to be added by 1 in value.

I have tried fiddling around with this for a while now and I can’t figure it out since when I remove child it gets errors. Here’s the code:

var eggClickOffset:Point = null;
var egg:Egg = new Egg();
egg.x = 290;
egg.y = 330;
addChild(egg);
var eggAmount:TextField = new TextField();
eggAmount.defaultTextFormat = textFormat;
eggAmount.x = 250;
eggAmount.y = 60;
eggAmount.height = 18;
eggAmount.width = 100;
eggAmount.border = true;
eggAmount.text = "Incorrect Amount";
eggAmount.background = true;
eggAmount.backgroundColor = 0xff0000;
stage.focus = eggAmount;
addChild(eggAmount);
var eggs:int;
eggs = 0;

//Egg Event listeners:
egg.addEventListener(Event.ENTER_FRAME, eggAmountCounter);
egg.addEventListener(MouseEvent.MOUSE_DOWN, startEggDrag);
egg.addEventListener(MouseEvent.MOUSE_UP, stopEggDrag);
egg.addEventListener(Event.ENTER_FRAME, dragEgg);
egg.addEventListener(Event.ENTER_FRAME, checkEggCollision);

//starting egg drag:
function startEggDrag(event:MouseEvent):void
{
    eggClickOffset = new Point(event.localX,event.localY);
}

//Stopping the egg drag:
function stopEggDrag(event:MouseEvent):void
{
    eggClickOffset = null;
}

//Egg Dragging:
function dragEgg(event:Event):void
{
    if (eggClickOffset != null)
    {// must be dragging
        egg.x = mouseX - eggClickOffset.x;
        egg.y = mouseY - eggClickOffset.y;
    }
}

//When egg hits jug:
function checkEggCollision(event:Event):void
{
    if (jug.hitTestObject(egg))
    {
            eggs + 1;
            egg.removeEventListener(MouseEvent.MOUSE_DOWN, startEggDrag);
            egg.removeEventListener(Event.ENTER_FRAME, dragEgg);
            removeChild(egg);
            addChild(egg);
            egg.x = 300;
            egg.y = 300;
    }
}

//How many eggs:
function eggAmountCounter(event:Event):void {
    if(eggs == 3){
        eggAmount.text = "Corrent Amount";
    }
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T13:14:19+00:00Added an answer on May 31, 2026 at 1:14 pm

    So adding and removing things from containers is actually quite expensive in terms of what the toolkit has to do to redraw itself. And there is usually problems like this you encounter where it just doesn’t work as advertised. So my suggestion to you is never add/remove components when you want to control visibility. Simply mark them visible=false/true, and optionally remember to use includeInLayout=true/false. Since you have movie clips visible=true/false should be good enough.

    If you just want the egg to start back at its original position just simply modify its x,y location directly. I’d create a simple method that takes in an egg and sets all of the properties for the initial state. In your stopEggDrag method simply call that function passing the egg that was being drug on the screen. Viola it pops back to where it was.

    The trick here is that you don’t have to solve the remove problem if you never remove the object.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Basically there is a file called 8puzzle.py and I want to import the file
Basically what I want to do it this: a pdb file contains a location
Basically I want to know how to set center alignment for a cell using
Basically I'm attempting to add rows to a table, I need to do this
Basically I have an IFRAME that contains a given page - I want to
Basically I want to get a handle of the python interpreter so I can
Basically when user resizes my application's window I want application to be same size
Basically I have a field in my table called sex, and it's a boolean.
Basically I have a loop incrementing i, and I want to do this: var
Basically, what I want is to access the data between substrings (between name: and

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.