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

  • Home
  • SEARCH
  • 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 7883665
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T04:35:38+00:00 2026-06-03T04:35:38+00:00

I have created a program in Actionscript 3 (Flash CS5) that spawns an Egg

  • 0

I have created a program in Actionscript 3 (Flash CS5) that spawns an Egg (a circle for now) off the stage when you click, and then sends the Egg to where you clicked with a (coded) tween. Additionally, it scales it in attempt to give an illusion of 3D.

I add a TweenEvent.MOTION_FINISH to one of the tweens for the Egg, to check when the motion finishes. When it does, I create a new object (called Splat) with the same coordinates as the original mouse click.

Problem 1: The Splat object isn’t added in the correct spot, as seen in the picture below. I check the coordinates, and they match in both the Egg class and the Splash class. I have also made sure that the registration point for both objects is in the middle of them. Finally, I have checked to see if it was the scale that made the problem, but I get the same problem even if I remove the scale tweens.

(EDIT: The Egg is placed in the right spot. The original coordinates for the mouse click are as they should be. It is ONLY the star objects that seem to be displaced.)

http://i45.tinypic.com/24bj1h3.png

Problem 2: The Splat object is scaled down the same amount as the Egg object. Why is this? I haven’t (intended to) make the Splash dependent on the Egg.

And here is the relevant code:

package  
{
import flash.display.MovieClip;
import flash.utils.Timer;
import flash.events.MouseEvent;

public class eggMain extends MovieClip
{
    import flash.events.Event;

    public function eggMain() 
    {
        stage.addEventListener(MouseEvent.CLICK, spawn);
    }

    function spawn(event)
    {
        for(var i:int = 0; i<1; i++)
        {
            trace("mX in main class = " + mouseX);
            trace("mY in main class = " + mouseY);
            var e:Egg = new Egg(mouseX, mouseY);
            addChild(e);

        }
    }
}
}


package  
{
import flash.display.MovieClip;
import fl.transitions.Tween;
import fl.transitions.easing.*;
import fl.transitions.TweenEvent;


public class Egg extends MovieClip 
{
    var stageWidth:int = 550;
    var stageHeight:int = 400;
    var buffer:int = 100;
    var mX = 0;
    var mY = 0;

    public function Egg(moX:int, moY:int) //mouseX, mouseY
    {
        mX = moX;
        mY = moY;
        trace("mX in Egg constructor: " + mX);
        trace("mY in Egg constructor: " + mY);

        spawnAtFixedPoint();
        animate();
    }




    function spawnAtFixedPoint()
    {
        this.x = stageWidth + buffer;
        this.y = stageHeight - buffer;
    }

    //Moves the egg in from the spawn point using tweens. Scales down on the way to give 3D illusion.
    function animate()
    {
        var xMovement:Tween;
        var yMovement:Tween;
        var xScale:Tween;
        var yScale:Tween;

        trace("mX in animate() = " + mX);
        trace("mY in animate() = " + mY);
        xMovement = new Tween(this, "x", Regular.easeOut, this.x, mX, 1, true); //obj, property, ease function, start, time, in seconds (true)
        yMovement = new Tween(this, "y", Regular.easeOut, this.y, mY, 1, true);
        xScale = new Tween(this, "scaleX", Regular.easeIn, 1, 0.1, 1, true);
        yScale = new Tween(this, "scaleY", Regular.easeIn, 1, 0.1, 1, true);


        //Checks when the object has finished animating (which mean the egg has landed)
        xMovement.addEventListener(TweenEvent.MOTION_FINISH, splat);
    }

    //Spawns a splat (currently a star) at the same coordinates as the egg
    function splat(event)
    {
        trace("mX in splat() = " + mX);
        trace("mY in splat() = " + mY);
        var s = new Splat(mX, mY);
        addChild(s);
    }

}
}

Update:
I created a custom SplatEvent and had my main class listen for it. The even is dispatched in the MOTION_FINISHED handler. It works!

Although, I had to make it work by using public static vars in the main class for passing back the original coordinates of the Egg landing. Like so in the main class:

public static var splatX:int;
public static var splatY:int;

And like this in the Egg class:

eggMain.splatX = mX;
eggMain.splatY = mY;

I can live with it, but I would prefer not to use global variables. Taking suggestions for this, although the main question is answered. Thanks.

  • 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-06-03T04:35:39+00:00Added an answer on June 3, 2026 at 4:35 am

    You’re creating the splat within the egg instance and then adding it to the egg’s display list. This means that the splat (star) is created in the egg’s coordinate space and is therefore offset by the egg’s position on the stage. It also means that the splat inherits any transformations you’ve made to the egg, such as the scale, as it is a child of the transformed egg instance.

    A better approach would be to listen in your main class for either your egg’s motion finish event (have a look at event bubbling) or a custom event fired from the motion finish handler. When that event is received, create an instance of splat and add it to the display list of the main class.

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

Sidebar

Related Questions

I have created a C# program that can dial a phone. Now what I
I have created a non-form c# program that uses the NotifyIcon class. The text
I have created a program that write video stream to a named pipe on
I have created a program that decrypts whats stored in a export file from
I have created a program that opens image files. How can I make my
A calculator program I have created works almost perfectly with the exception that Math.Sin()
I have created a little program that reads in a Java file and feeds
I have created a program in Java using eclipse that contains a couple of
I have created a program in C++ but I want that the program download
I have created a program in c++ that doesn't have any GUI. When this

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.