flash on 2011-4-26
mspaintadventures.com/?s=6&p=002340
/**
* Copyright wgoldie42 ( http://wonderfl.net/user/wgoldie42 )
* MIT License ( http://www.opensource.org/licenses/mit-license.php )
* Downloaded from: http://wonderfl.net/c/h82N
*/
package {
import flash.ui.Keyboard;
import flash.text.TextField;
import flash.events.KeyboardEvent;
import flash.events.Event;
import flash.display.BitmapData;
import flash.geom.Rectangle;
import flash.display.Sprite;
import flash.display.Bitmap;
import flash.events.*;
import flash.net.*;
import flash.display.Loader;
import flash.display.LoaderInfo;
import flash.system.LoaderContext;
public class FlashTest extends Sprite {
private var bmpD:BitmapData = new BitmapData(30,30, false, 0x00000FF);
public var bmp:Bitmap = new Bitmap(bmpD);
public var textBox:TextField = new TextField();
public var xAccl:Number = 0;
public var yAccl:Number = 0;
public var xSpeed:Number = 0;
public var ySpeed:Number = 0;
public var jumping:Boolean = false;
private var loader:Loader = new Loader( );
private var bd: BitmapData;
public function FlashTest() {
this.addChild(bmp);
this.addEventListener(Event.ENTER_FRAME, perFrame);
stage.addEventListener(KeyboardEvent.KEY_DOWN, kDown);
inittrace(stage);
init();
}
private function perFrame(e:Event):void{
moveThis();
// trace("Frame");
}
private function kDown(e:KeyboardEvent):void
{
//trace(e.keyCode);
//up
if(e.keyCode==87 && jumping==false){
yAccl-=4;
jumping=true;
}
//down
//left
if(e.keyCode==65){
xAccl-=3;
}
if(e.keyCode==68){
xAccl+=3;
}
}
private function moveThis():void
{
if(xAccl > 2)
{
xAccl = 2;
}
if(xAccl < -10) {
xAccl = -10;
}
if(yAccl > 2)
{
yAccl = 2;
}
ySpeed+=yAccl;
xSpeed+=xAccl;
// trace("Should move here");
if(ySpeed > 10) {
ySpeed = 10;
}
if(xSpeed > 10) {
xSpeed = 10;
}
if(ySpeed < -10) {
ySpeed = -10;
}
if(xSpeed <-10) {
xSpeed = -10;
}
bmp.x+=xSpeed;
bmp.y+=ySpeed;
if(bmp.y < bmp.height) {
bmp.y = height;
ySpeed= 0;
}
if(bmp.y > (465 - bmp.height)){
bmp.y = (465 - bmp.height);
ySpeed= 0;
jumping= false;
}
if(bmp.x < bmp.width) {
bmp.x = width;
xSpeed= 0;
}
if(bmp.x > (465 - bmp.width)){
bmp.x = (465 - bmp.width);
xSpeed= 0;
}
xAccl*=0.80;
yAccl*=0.80;
this.ySpeed+=1;
}
private static const URL:String = "http://i.dimgur.com/bj8Bw.jpg";
private function init():void
{
var loader:Loader = new Loader();
loader.contentLoaderInfo.addEventListener(Event.COMPLETE , complete);
loader.load(new URLRequest(URL), new LoaderContext(true));
}
private function complete(e:Event):void
{
var loaderInfo:LoaderInfo = e.target as LoaderInfo;
loaderInfo.removeEventListener(Event.COMPLETE , complete);
var bm:Bitmap = loaderInfo.content as Bitmap;
var bmd:BitmapData = bm.bitmapData;
var bmd2:BitmapData;
this.addChild(loaderInfo.content);
}
}
}
///// WONDERFL TRACE /////
import flash.display.Sprite;
import flash.display.Stage;
import flash.text.TextField;
import flash.text.TextFormat;
function inittrace(s:Stage):void
{
WTrace.initTrace(s);
}
//global trace function
var trace:Function;
//wtreace class
class WTrace
{
private static var FONT:String = "Fixedsys";
private static var SIZE:Number = 12;
private static var TextFields:Array = [];
private static var trace_stage:Stage;
public static function initTrace(stg:Stage):void
{
trace_stage = stg;
trace = wtrace;
}
private static function scrollup():void
{
// maximum number of lines: 100
if (TextFields.length > 100)
{
var removeme:TextField = TextFields.shift();
trace_stage.removeChild(removeme);
removeme = null;
}
for(var x:Number=0;x<TextFields.length;x++)
{
(TextFields[x] as TextField).y -= SIZE*1.2;
}
}
public static function wtrace(... args):void
{
var s:String="";
var tracefield:TextField;
for (var i:int;i < args.length;i++)
{
// imitating flash:
// putting a space between the parameters
if (i != 0) s+=" ";
s+=args[i].toString();
}
tracefield= new TextField();
tracefield.autoSize = "left";
tracefield.text = s;
tracefield.y = trace_stage.stageHeight - 20;
var tf:TextFormat = new TextFormat(FONT, SIZE);
tracefield.setTextFormat(tf);
trace_stage.addChild(tracefield);
scrollup();
TextFields.push(tracefield);
}
}