AS3.0 How to get a movieclip to avoid cursor?
hello everyone,
i trying recreate simple interactive application movieclip, mybutterfly, avoids cursor, , @ same time restricted within specific boundary set rectangle object. having trouble getting work. there specific process asked follow , appreciate if can point me in right direction, or me out. here specifications , code have far.
specifications:
- i need define following variables:
- to store values: 15,40,285,185 rectangle
- to store speed of butterfly: 5
- to store distance, mouse needs butterfly affect it: 20
- to store direction of movement in x direction. use 1 indicate movement right , -1 move left.
- to store direction of movement in y direction. use 1 indicate movement downward, , -1 move upward.
- i need add listener detect mouse moves.
- i should define function named avoidme handle behavior of butterfly.
- within function, need to:
- use if statements determine direction move butterfly both vertically , horizontally , set direction variables accordingly
- move butterfly multiplying speed , direction variables
- keep butterfly within boundaries specified rectangle object
here code have far:
//variable definition
//rectangle boundaries
import flash.geom.rectangle;
import flash.ui.mouse;
import flash.events.event;
var xlocation:number = 10;
var ylocation:number = 10;
var widthofrect:number = 270;
var heightofrect:number = 170;
var rectboundary:rectangle = new rectangle(xlocation, ylocation, widthofrect, heightofrect);
trace(rectboundary)
// butterfly speed
var butterflyspeed:number = 5;
// mouse distance butterfly
var mousedistance:number = 20;
// movement direction
/* need define direction variables here
one x , 1 y. these contain values 1 or -1
i not sure if should use array here or not */
// avoidme function
stage.addeventlistener(event.enter_frame,avoidme);
function avoidme(event:event):void {
//if butterfly within 20 pixels of mouse
//think how determine - involves finding difference
//between mousex , butterfly's x position y positions
//
//next check see if mouse on left or right of butterfly
//if mouse on left want move butterfly right
//otherwise want move left.
//to move left need subtract, move right need add
//so here direction variables should have declared above come in.
//i need set direction variable either 1 or -1
// need same thing y , set direction variables
//now using direction variables, need move butterfly multiplying
//the direction variables speed , adding result current
//position of butterfly followed adding or subtracting speed
//to check see if it's within boundaries, nee compare position of butterfly
//with left,right, top , bottom properties of rectangle object
//if butterfly out of bounds, need move in. might have offset the
//position butterfly's width or height since registration point in middle
//of buttefly
}
help me!!!
why there such restrictions on how this? school assignment? problem having interpretting instructions outlined in avoidme function form of code?
More discussions in ActionScript 3
adobe
Comments
Post a Comment