Sunday, February 25, 2007

contolling objects in FlashMX


tool : Flash MX

Moving object as movie clips in Flash can be achieved in various ways. One of them is controlling objects with text input box.
First, create new file. You will need two things, movieclip that represents object, and button with input text box. My creations are on picture below.



For button, for every state put keyframe. Set show border around text. Set input text with var : "distance".
Set movieclip instance name as "wheel". Finaly enter action for button:

on(keyPress "< Enter>"){
  _root.onEnterFrame=function(){
    if (_root.wheel._x < distance){
      _root.wheel._x += 5;
      _root.wheel._rotation +=5;
    }
    if (_root.wheel._x > distance){
      _root.wheel._x -= 5;
      _root.wheel._rotation -=5;
    }
  }
}

Another way of moving movieclip is with mouse. In this case we don't have button. MovieClip is same, and only code is in first frame of main timeline.
_root.onEnterFrame=function(){
  if (_root.wheel._x < _xmouse){
    _root.wheel._x += 10;
    _root.wheel._rotation +=10;
  }
  if (_root.wheel._x > _xmouse){
    _root.wheel._x -= 10;
    _root.wheel._rotation -=10;
  }
}
Posted by flanture at 23:13:12 | Permanent Link | Comments (0) |
Comments
Write a comment