Ball eats the mouse and when you shake the mouse it falls

  • amexudo
  • Born
  • Born
  • amexudo
  • Posts: 2

Post 3+ Months Ago

Hello everyone,
i am not very experienced in developing but i am trying to make a flash website and cannot make one thing work: Inside the "Who are we?" page of the attached swf (click on "Who are we?") there is a ball that jumps from the water and i would like it to behavior in a way that when the mouse approaches the ball, it eats the mouse and the mouse disappears. And when the ball is moving within the mouse, if you shake the mouse, it falls.
I cannot obtain the effect i would like.
Can someone try to give me directions?
Thank you and i hope you enjoy my site's design.

Code: [ Select ]
package
{
    import fl.transitions.*;
    import fl.transitions.easing.*;
    
    import flash.display.MovieClip;
    import flash.events.*;
    import flash.ui.Mouse;
    import flash.utils.Timer;
    
    public class MyBall extends MovieClip
    {
        
        private const MOUSE_CLOSE:String = "mouse close";
        private const MOUSE_SHAKE:String = "mouse shake";
        public var glued:Boolean;//whether the ball is glued to mouse or not
        private var _count:Number = 0;//counts how many times the user shakes the mouse
        private var lastMouseX:Number;
        private var lastMouseY:Number;
        private var fishTimer:Timer;
        private var myTimer:Timer;
        private var myTimer2:Timer;
        private var _myTweenX:Tween;
        private var _myTweenY:Tween;
        private var _edge:Boolean;
        private var _sideMove:Number;
        private var evt:Event;//event of approaching the mouse to the ball
        private var evt2:Event;//event of shaking the mouse
        
        public function MyBall()
        {
            this.x = 149.3;
            this.y = 555.3;
            this._sideMove = 100;
            this.glued = false;
            this.fishTimer = new Timer(1500);
            this.fishTimer.addEventListener(TimerEvent.TIMER,onTimerJump);
            this.fishTimer.start();
            evt = new Event(MOUSE_CLOSE);//event of approaching the mouse to the ball
            evt2 = new Event(MOUSE_SHAKE);//event of shaking the mouse
            this.myTimer = new Timer(5);
            this.myTimer.start();
            this.myTimer.addEventListener(TimerEvent.TIMER, onTimerEvent);
            addEventListener(this.MOUSE_CLOSE, onMouseClose);
            this.myTimer2 = new Timer(5);
            this.myTimer2.start();
            this.myTimer2.addEventListener(TimerEvent.TIMER, onTimer2);
        }
        
        
        //timer that the ball flies when it's not glued to the mouse
        private function onTimerJump(e:TimerEvent):void
        {
            if(this.glued == false)
            {
                this.fly();
            }
        }
        
        public function fly():void
        {
            if ((this.x > 530) || (this.x <100))
            {
                _edge = true;
            }
            else
            {
                _edge = false;
            }
            
            if(_edge)
            {
                _sideMove *= -1;
            }
                
            this._myTweenX = new Tween(this, "x", None.easeOut, this.x, this.x + _sideMove , 1.1, true);
            this._myTweenY = new Tween(this, "y", Strong.easeOut, this.y, this.y - 200, 0.6, true);
            this._myTweenY.addEventListener(TweenEvent.MOTION_FINISH, onTweenYEnd);
            
            
        }
        
        private function onTweenYEnd(e:TweenEvent):void
        {
            this._myTweenY = new Tween(this, "y", Strong.easeOut, this.y, this.y + 200, 1.1, true);
            this._myTweenX = new Tween(this, "x", Strong.easeOut, this.x, this.x + _sideMove/2, 0.6, true);
        }
        
        
        
        
        private function onMouseClose(e:Event):void {
            this.glued = true;
            addEventListener(MOUSE_SHAKE, onMouseShake);
        }
        
        //timer that checks if the mouse is close to the ball
        private function onTimerEvent(e:TimerEvent):void {
                
            if ((Math.abs(this.x - stage.mouseX) < 40) && (Math.abs(this.y - stage.mouseY) < 40)) {
                dispatchEvent(evt);//event of approaching the mouse to the ball
                this.fishTimer.stop();
            }
            
                    
            if (this.glued == true) {
                Mouse.hide();
                this.x = stage.mouseX;
                this.y = stage.mouseY;
                this.myTimer2.addEventListener(TimerEvent.TIMER,onTimer2);
                this.myTimer.addEventListener(TimerEvent.TIMER, onTimerEvent);
            }
            else {
                this.fishTimer.start();
            }
        }
        
        //timer for when the ball is glued
        function onTimer2(e:TimerEvent):void {
            if ((Math.abs(lastMouseX - stage.mouseX)>120) || (Math.abs(lastMouseY - stage.mouseY)>120)) {
                _count++;
            }
            else {
                _count = 0;
            }
            lastMouseX = mouseX;
            lastMouseY = mouseY;
            if (_count == 6) {
                dispatchEvent(evt2);//event of shaking the mouse
                _count = 0;
                //trace("shaked");
                removeEventListener(MOUSE_SHAKE, onMouseShake);
                
            }
        }
        
        //when the user shakes the mouse, the ball falls down
        function onMouseShake(e:Event):void {
            this.glued = false;
            this._myTweenY = new Tween(this,"y",None.easeIn,this.y, 500, 3);
            this.x = 149.3;
            this.y = 535.3;
            Mouse.show();
            this.fishTimer.start();
            addEventListener(MOUSE_CLOSE, onMouseClose);
        }
    }
}
  1. package
  2. {
  3.     import fl.transitions.*;
  4.     import fl.transitions.easing.*;
  5.     
  6.     import flash.display.MovieClip;
  7.     import flash.events.*;
  8.     import flash.ui.Mouse;
  9.     import flash.utils.Timer;
  10.     
  11.     public class MyBall extends MovieClip
  12.     {
  13.         
  14.         private const MOUSE_CLOSE:String = "mouse close";
  15.         private const MOUSE_SHAKE:String = "mouse shake";
  16.         public var glued:Boolean;//whether the ball is glued to mouse or not
  17.         private var _count:Number = 0;//counts how many times the user shakes the mouse
  18.         private var lastMouseX:Number;
  19.         private var lastMouseY:Number;
  20.         private var fishTimer:Timer;
  21.         private var myTimer:Timer;
  22.         private var myTimer2:Timer;
  23.         private var _myTweenX:Tween;
  24.         private var _myTweenY:Tween;
  25.         private var _edge:Boolean;
  26.         private var _sideMove:Number;
  27.         private var evt:Event;//event of approaching the mouse to the ball
  28.         private var evt2:Event;//event of shaking the mouse
  29.         
  30.         public function MyBall()
  31.         {
  32.             this.x = 149.3;
  33.             this.y = 555.3;
  34.             this._sideMove = 100;
  35.             this.glued = false;
  36.             this.fishTimer = new Timer(1500);
  37.             this.fishTimer.addEventListener(TimerEvent.TIMER,onTimerJump);
  38.             this.fishTimer.start();
  39.             evt = new Event(MOUSE_CLOSE);//event of approaching the mouse to the ball
  40.             evt2 = new Event(MOUSE_SHAKE);//event of shaking the mouse
  41.             this.myTimer = new Timer(5);
  42.             this.myTimer.start();
  43.             this.myTimer.addEventListener(TimerEvent.TIMER, onTimerEvent);
  44.             addEventListener(this.MOUSE_CLOSE, onMouseClose);
  45.             this.myTimer2 = new Timer(5);
  46.             this.myTimer2.start();
  47.             this.myTimer2.addEventListener(TimerEvent.TIMER, onTimer2);
  48.         }
  49.         
  50.         
  51.         //timer that the ball flies when it's not glued to the mouse
  52.         private function onTimerJump(e:TimerEvent):void
  53.         {
  54.             if(this.glued == false)
  55.             {
  56.                 this.fly();
  57.             }
  58.         }
  59.         
  60.         public function fly():void
  61.         {
  62.             if ((this.x > 530) || (this.x <100))
  63.             {
  64.                 _edge = true;
  65.             }
  66.             else
  67.             {
  68.                 _edge = false;
  69.             }
  70.             
  71.             if(_edge)
  72.             {
  73.                 _sideMove *= -1;
  74.             }
  75.                 
  76.             this._myTweenX = new Tween(this, "x", None.easeOut, this.x, this.x + _sideMove , 1.1, true);
  77.             this._myTweenY = new Tween(this, "y", Strong.easeOut, this.y, this.y - 200, 0.6, true);
  78.             this._myTweenY.addEventListener(TweenEvent.MOTION_FINISH, onTweenYEnd);
  79.             
  80.             
  81.         }
  82.         
  83.         private function onTweenYEnd(e:TweenEvent):void
  84.         {
  85.             this._myTweenY = new Tween(this, "y", Strong.easeOut, this.y, this.y + 200, 1.1, true);
  86.             this._myTweenX = new Tween(this, "x", Strong.easeOut, this.x, this.x + _sideMove/2, 0.6, true);
  87.         }
  88.         
  89.         
  90.         
  91.         
  92.         private function onMouseClose(e:Event):void {
  93.             this.glued = true;
  94.             addEventListener(MOUSE_SHAKE, onMouseShake);
  95.         }
  96.         
  97.         //timer that checks if the mouse is close to the ball
  98.         private function onTimerEvent(e:TimerEvent):void {
  99.                 
  100.             if ((Math.abs(this.x - stage.mouseX) < 40) && (Math.abs(this.y - stage.mouseY) < 40)) {
  101.                 dispatchEvent(evt);//event of approaching the mouse to the ball
  102.                 this.fishTimer.stop();
  103.             }
  104.             
  105.                     
  106.             if (this.glued == true) {
  107.                 Mouse.hide();
  108.                 this.x = stage.mouseX;
  109.                 this.y = stage.mouseY;
  110.                 this.myTimer2.addEventListener(TimerEvent.TIMER,onTimer2);
  111.                 this.myTimer.addEventListener(TimerEvent.TIMER, onTimerEvent);
  112.             }
  113.             else {
  114.                 this.fishTimer.start();
  115.             }
  116.         }
  117.         
  118.         //timer for when the ball is glued
  119.         function onTimer2(e:TimerEvent):void {
  120.             if ((Math.abs(lastMouseX - stage.mouseX)>120) || (Math.abs(lastMouseY - stage.mouseY)>120)) {
  121.                 _count++;
  122.             }
  123.             else {
  124.                 _count = 0;
  125.             }
  126.             lastMouseX = mouseX;
  127.             lastMouseY = mouseY;
  128.             if (_count == 6) {
  129.                 dispatchEvent(evt2);//event of shaking the mouse
  130.                 _count = 0;
  131.                 //trace("shaked");
  132.                 removeEventListener(MOUSE_SHAKE, onMouseShake);
  133.                 
  134.             }
  135.         }
  136.         
  137.         //when the user shakes the mouse, the ball falls down
  138.         function onMouseShake(e:Event):void {
  139.             this.glued = false;
  140.             this._myTweenY = new Tween(this,"y",None.easeIn,this.y, 500, 3);
  141.             this.x = 149.3;
  142.             this.y = 535.3;
  143.             Mouse.show();
  144.             this.fishTimer.start();
  145.             addEventListener(MOUSE_CLOSE, onMouseClose);
  146.         }
  147.     }
  148. }
  • amexudo
  • Born
  • Born
  • amexudo
  • Posts: 2

Post 3+ Months Ago

http://www.dreamfarmer.com/ - this is the website
  • Flanders
  • Beginner
  • Beginner
  • User avatar
  • Posts: 48
  • Loc: Reno, Nevada US

Post 3+ Months Ago

I like the graphics on the home page. Pretty cool. I can't really answer your question though.

Post Information

  • Total Posts in this topic: 3 posts
  • Users browsing this forum: No registered users and 10 guests
  • You cannot post new topics in this forum
  • You cannot reply to topics in this forum
  • You cannot edit your posts in this forum
  • You cannot delete your posts in this forum
  • You cannot post attachments in this forum
 
cron
 

© 1998-2014. Ozzu® is a registered trademark of Unmelted, LLC.