In case Flash no longer exists; a copy of this site is included in the Flashpoint archive's "ultimate" collection.

Dead Code Preservation :: Archived AS3 works from wonderfl.net

Moving ball

Get Adobe Flash player
by Pelisalinet 14 Oct 2012
/**
 * Copyright Pelisalinet ( http://wonderfl.net/user/Pelisalinet )
 * MIT License ( http://www.opensource.org/licenses/mit-license.php )
 * Downloaded from: http://wonderfl.net/c/uzgo
 */

package {
    import flash.text.TextField;
    import flash.display.*;
    import flash.events.*;
    import flash.ui.*;
    public class FlashTest extends Sprite {
        public function FlashTest() {
            
            var wiiplayer:WiiPlayer = new WiiPlayer();
            var wiihandler:WiiHandler = new WiiHandler();
            
            wiiplayer.addPlayer(20,20,10,0x0,5);
            
            var i:int = 0;
            
            /*for(i=0; i <= wiiplayer.players.length; i++){
                stage.addChild(wiiplayer.drawPlayer(i));
            }*/
            
            var player1:MovieClip = wiiplayer.drawPlayer(0);
            
            player1.keyUp = false;
            player1.keyDown = false;
            player1.keyLeft = false;
            player1.keyRight = false;
            
            stage.addEventListener(KeyboardEvent.KEY_DOWN,function(k:KeyboardEvent):void{
                switch(k.keyCode){
                    case Keyboard.UP:
                    player1.keyUp = true;
                    break;
                    case Keyboard.DOWN:
                    player1.keyDown = true;
                    break;
                    case Keyboard.LEFT:
                    player1.keyLeft = true;
                    break;
                    case Keyboard.RIGHT:
                    player1.keyRight = true;
                    break;
                }
            });
            
            stage.addEventListener(KeyboardEvent.KEY_UP,function(k:KeyboardEvent):void{
                switch(k.keyCode){
                    case Keyboard.UP:
                    player1.keyUp = false;
                    break;
                    case Keyboard.DOWN:
                    player1.keyDown = false;
                    break;
                    case Keyboard.LEFT:
                    player1.keyLeft = false;
                    break;
                    case Keyboard.RIGHT:
                    player1.keyRight = false
                    break;
                }
            });
            
            this.addEventListener(Event.ENTER_FRAME,function(e:Event):void{
                if(player1.keyUp){
                    wiiplayer.players[0].y-=wiiplayer.players[0].speed;
                }
                if(player1.keyDown){
                    wiiplayer.players[0].y+=wiiplayer.players[0].speed;  
                }
                if(player1.keyLeft){
                    wiiplayer.players[0].x-=wiiplayer.players[0].speed;
                }
                if(player1.keyRight){
                    wiiplayer.players[0].x+=wiiplayer.players[0].speed; 
                }


                
                player1.x = wiiplayer.players[0].x;
                player1.y = wiiplayer.players[0].y;
               
                wiihandler.updateHandler(); 
                
            });

            stage.addChild(player1);
                      
        }
    }
}
import flash.utils.ObjectInput;

import flash.display.*;
class WiiPlayer extends Sprite {
    
public var players:Array = [];
public var playersGrap:Array = [];

public function WiiPlayer(){
    
}

public function addPlayer(_x:int=0,_y:int=0,_radius:int=5,_color:uint=0x0,_speed:int=1):void {
    var playerObject:Object = new Object();
    playerObject.y = _y;
    playerObject.x = _x;
    playerObject.radius = _radius;
    playerObject.color = _color;
    playerObject.speed = _speed;
    
    players.push(playerObject);
}

public function drawPlayer(id:int=0):MovieClip {
    var ball:MovieClip = new MovieClip();
    ball.graphics.beginFill(0);
    ball.graphics.drawCircle(0, 0, players[id].radius);
    ball.x = players[id].x;
    ball.y = players[id].y;
    playersGrap.push(ball);
    return ball;
}

public function updatePlayer(id:int=0):void{
    playersGrap[id].y = players[id].y;
    playersGrap[id].x = players[id].y;
}


}

import flash.events.*;
import flash.display.*;
class WiiHandler extends Sprite {
    
public var yPos:int = 0;
public var xPos:int = 0;

public function WiiHandler(){
    
}

public function updateHandler():void {
    yPos = stage.mouseY;
    xPos = stage.mouseX;
}


public function getHandlerPosition():Array{
    var posArray:Array = [yPos,xPos];
    return posArray;
}


}