Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Aug 10th, 2012  |  syntax: None  |  size: 1.41 KB  |  hits: 8  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. import flash.events.Event;
  2. import com.whirled.AvatarControl;
  3.  
  4. if (_ctrl == null) {
  5.         _ctrl = new AvatarControl(this);
  6.         _body = new Body(_ctrl, this, 240);
  7.         _ctrl.addEventListener(Event.UNLOAD, handleUnload);
  8.         function handleUnload (... ignored) :void {
  9.                 _body.shutdown();
  10.         }
  11. }
  12.  
  13. var _ctrl :AvatarControl;
  14. var _body :Body;
  15.  
  16. //Change the 0.2 below to change how high above the floor the avatar will appear once it is moved. 0 is the floor and 1 is the ceiling
  17. function fly():void{
  18.         updateRoom();
  19.         flyHeight = (roomSize[1] as int)*0.4;
  20.         _ctrl.setPreferredY(flyHeight);
  21. }
  22.  
  23. function unFly():void{
  24.         _ctrl.setPreferredY(0);
  25. }
  26.  
  27. function updateRoom():void{
  28.         roomSize = _ctrl.getRoomBounds();      
  29. }
  30.  
  31. var flyHeight:int = 0;
  32. var roomSize:Array = new Array(100,100,100);
  33.  
  34. _ctrl.addEventListener(ControlEvent.STATE_CHANGED, stateHandler);
  35. _ctrl.addEventListener(ControlEvent.ACTION_TRIGGERED, actionHandler);
  36.  
  37.  
  38. function stateCodeSwitch ()
  39. {
  40.         switch (_ctrl.getState())
  41.         {
  42.                 case "land":
  43.                 //code
  44.                 break;
  45.                 case "Fly":
  46.                 //code
  47.                 break;
  48.                 /*
  49.                 just keep adding
  50.                 case "<statenamehere>":
  51.                 //code for that state like hotspot and movespeed
  52.                 break;
  53.                 for any other states you want to have altered coding for
  54.                 */
  55.                 default:
  56.                 //The hotspot and movespeed for the avatar when it's normal goes here
  57.                 break;
  58.         }
  59. }
  60.  
  61.  
  62. function stateHandler (event:ControlEvent)
  63. {
  64.         stateCodeSwitch();
  65. }