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 8852039
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T13:18:11+00:00 2026-06-14T13:18:11+00:00

I’m really new to flash and as3… I’m trying to create 2 scenes in

  • 0

I’m really new to flash and as3…
I’m trying to create 2 scenes in flash – one where my movieclip moves away from the mouse whenever it goes near it, and the other where the movie clip is attracted to the mouse. I have found an answer on actionscript 2 but i cannot use this in my as3 file…
Any help or ideas?
Cheers!

  • 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-14T13:18:13+00:00Added an answer on June 14, 2026 at 1:18 pm

    Here is an example I made of a display object being “pushed” and “pulled” in relation to the mouse’s position.

    Main.as(Document class):

    package 
    {
        import flash.display.Sprite;
        import flash.events.Event;
        import flash.events.MouseEvent;
        import flash.geom.Point;
    
        public class Main extends Sprite  
        {
    
            public static var PULL:String = "pull";
            public static var PUSH:String = "push";
    
            private var _circle:Circle;
            private var _force:String;
    
            public function Main():void 
            {
                if (stage) init();
                else addEventListener(Event.ADDED_TO_STAGE, init);
    
            }// end function
    
            private function init(e:Event = null):void 
            {
                removeEventListener(Event.ADDED_TO_STAGE, init);
    
                _circle = new Circle();
                addChild(_circle);
    
                _force = PULL;
    
                stage.addEventListener(MouseEvent.MOUSE_DOWN, onStageMouseDown);
    
            }// end function
    
            private function onStageMouseDown(e:MouseEvent):void 
            {
                stage.addEventListener(MouseEvent.MOUSE_UP, onStageMouseUp);
                stage.addEventListener(Event.ENTER_FRAME, onStageEnterFrame);
    
            }// end function
    
            private function onStageMouseUp(e:MouseEvent):void 
            {
                stage.removeEventListener(MouseEvent.MOUSE_UP, onStageMouseUp);
                stage.removeEventListener(Event.ENTER_FRAME, onStageEnterFrame);
    
                _force = (_force == PULL) ? PUSH : PULL;
    
            }// end function
    
            private function onStageEnterFrame(e:Event):void 
            {
                var point1:Point = new Point(_circle.x, _circle.y);
                var point2:Point = new Point(stage.mouseX, stage.mouseY);
                var point3:Point = point2.subtract(point1);
                point3.normalize(10);
    
                if (_force == PULL) {
    
                    _circle.x += point3.x;
                    _circle.y += point3.y;
    
                } else if (_force == PUSH) {
    
                    _circle.x -= point3.x;
                    _circle.y -= point3.y;
    
                }// end else if
    
            }// end function
    
        }// end class
    
    }// end package
    
    import flash.display.Sprite;
    import flash.events.Event;
    
    class Circle extends Sprite {
    
        public function Circle() {
    
            draw();
    
        }// end function
    
        private function draw():void {
    
            this.graphics.lineStyle(1);
            this.graphics.beginFill(0xFFFFFF);
            this.graphics.drawCircle( 0, 0, 20);
            this.graphics.endFill();
    
        }// end function
    
    }// end class
    

    In the init() method we add a new display object to the stage, this is the display object we will be “pulling” and “pushing” in relation to the mouse’s position.

    _circle = new Circle();
    addChild(_circle);
    

    Then we set the _force property to our PULL constant. The _force property will determine whether the display object is “pulled” or “pushed”.

    _force = PULL;
    

    Next we add our mouse event listeners to the stage. On MouseEvent.MOUSE_DOWN we call the onStageMouseDown() event handler. When the handler is called, we add an Event.ENTER_FRAME and MouseEvent.MOUSE_UP event listeners to the stage.

    private function onStageMouseDown(e:MouseEvent):void 
    {
        stage.addEventListener(MouseEvent.MOUSE_UP, onStageMouseUp);
        stage.addEventListener(Event.ENTER_FRAME, onStageEnterFrame);
    
    }// end function
    

    When the MouseEvent.MOUSE_UP event handler is called, the previous Event.ENTER_FRAME and MouseEvent.MOUSE_UP event listeners are removed from the stage. Then depending on the _force property’s value, its value is alternated between PUSH and PULL.

    private function onStageMouseUp(e:MouseEvent):void 
    {
        stage.removeEventListener(MouseEvent.MOUSE_UP, onStageMouseUp);
        stage.removeEventListener(Event.ENTER_FRAME, onStageEnterFrame);
    
        _force = (_force == PULL) ? PUSH : PULL;
    
    }// end function
    

    Lastly, the onStageEnterFrame event handler. This is where we calculate the new position of the display object in relation to the mouse.

    There are different ways to go about this, but I decided to use the Point class to simplify things. First we have to get a Point object for the display object’s position and another Point object for mouse’s position.

    var point1:Point = new Point(_circle.x, _circle.y);
    var point2:Point = new Point(stage.mouseX, stage.mouseY);
    

    Next we have to get the difference between the points using the Point object’s subtract() method.

    var point3:Point = point2.subtract(point1);
    

    With this new point, we can use the Point object’s normalize() method to scale the line segment between the display object’s position and the mouse’s position to a set length.

    point3.normalize(10);
    

    Finally depending on the _force property’s value we either subtract or add the point’s x and y properties from the display object’s x and y properties.

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

Sidebar

Related Questions

I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I'm trying to create an if statement in PHP that prevents a single post
I'm trying to convert HTML to plain text. I get many &\#8217; &\#8220; etc.
I am reading a book about Javascript and jQuery and using one of the
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
link Im having trouble converting the html entites into html characters, (&# 8217;) i
For some reason, after submitting a string like this Jack’s Spindle from a text
I am trying to understand how to use SyndicationItem to display feed which is
I want use html5's new tag to play a wav file (currently only supported
I am trying to render a haml file in a javascript response like so:

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.