A Flash Developer Resource Site

Results 1 to 2 of 2

Thread: AS3 Wii

  1. #1
    Senior Member
    Join Date
    Mar 2010
    Posts
    107

    AS3 Wii

    Hey all,

    I posted earlier here about AS3 and Kinect: For the people who read about it, I didn't manage to do it yet since I am time short, so I choose for something else and that is connecting my Wii controller to my pc and combining it with AS3.

    It worked and I got my program working, but I have a question.

    Im trying to modify the speed of the movement of my wii controller. Now, the speed is limited to an annoyingly slow speed when moving my wii controller. I want it as fast as the user moves his controller. How is that possible?

    Here is the code:

    Actionscript Code:
    package
    {
        import flash.display.Sprite;
        import flash.events.Event;
        import flash.ui.Mouse;
        import org.wiiflash.events.ButtonEvent;
        import org.wiiflash.events.WiimoteEvent;
        import org.wiiflash.Wiimote;
       

        /**
         * ...
         * @author Marciano S.R Schildmeijer
         */

        public class Main extends Sprite
        {
            private var wiiMote:Wiimote;
            private var speed:int = 2;
           
            private var a:Boolean;
            private var b:Boolean;
            private var mousePointer:MousePointer;
            private var square:Square;
           
            public function Main():void
            {
                if (stage) init();
                else addEventListener(Event.ADDED_TO_STAGE, init);
            }
           
            private function init(e:Event = null):void
            {
                removeEventListener(Event.ADDED_TO_STAGE, init);
                // entry point
               
                createMousePointer();
               
                wiiMote = new Wiimote();
                wiiMote.connect();
           
               
                wiiMote.addEventListener(ButtonEvent.A_PRESS, press);
                wiiMote.addEventListener(ButtonEvent.A_RELEASE, release);
                wiiMote.addEventListener(ButtonEvent.B_PRESS, bPress);
                wiiMote.addEventListener(ButtonEvent.B_RELEASE, bRelease);
               
               
                wiiMote.addEventListener(WiimoteEvent.UPDATE, update);
               
           
           
            }
           
            private function createMousePointer():void
            {
                mousePointer = new MousePointer();
                addChild(mousePointer);
               
               
            }
           
            private function createSquareClass():void
            {
                square = new Square();
                addChild(square);
               
                square.x = mousePointer.x;
                square.y = mousePointer.y;
           
            }
           
            private function bPress(e:ButtonEvent):void
            {
                mousePointer.addEventListener(Event.ENTER_FRAME, loop);
                b = true;
               
            }
           
            private function bRelease(e:ButtonEvent):void
            {
                mousePointer.removeEventListener(Event.ENTER_FRAME, loop);
                b = false;
                mousePointer.alpha = 1;
            }
           
            private function update(e:WiimoteEvent):void
            {
               
                mousePointer.y += wiiMote.pitch;
                mousePointer.x += wiiMote.roll;
               
                //mousePointer.x = wiiMote.sensorX + 45;
               
           
       
            }
           
            private function loop(e:Event):void
            {
                if ( a )
                {
                    createSquareClass();
                   
                }
                if ( b )
                {
                    mousePointer.alpha = 0.5;
                }
               
               
           
               
            }
           
            private function release(e:ButtonEvent):void
            {
                trace("D");
                a = false;
                mousePointer.removeEventListener(Event.ENTER_FRAME, loop);
                wiiMote.rumble = false;
           
            }
           
            private function press(e:ButtonEvent):void
            {
                trace("press");
                a = true;
                wiiMote.rumble = true;
                mousePointer.addEventListener(Event.ENTER_FRAME, loop);
               
               
            }
           

           
        }
       
    }

    Thanks.

  2. #2
    Senior Member
    Join Date
    Mar 2010
    Posts
    107
    Anyone ? I just need to figure out how to use the wii controller as the current mouse, like MouseY and MouseX.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center