Ball eats the mouse and when you shake the mouse it falls
- amexudo
- Born


- Joined: May 05, 2009
- Posts: 2
- Status: Offline
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.
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);
}
}
}
{
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);
}
}
}
- 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);
- }
- }
- }
- Anonymous
- Bot


- Joined: 25 Feb 2008
- Posts: ?
- Loc: Ozzuland
- Status: Online
May 5th, 2009, 8:07 am
- amexudo
- Born


- Joined: May 05, 2009
- Posts: 2
- Status: Offline
Page 1 of 1
To Reply to this topic you need to LOGIN or REGISTER. It is free.
Post Information
- Total Posts in this topic: 3 posts
- Users browsing this forum: No registered users and 51 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

