pack开发者_如何学运维age { import flash.display.; import flash.events.; import flash.net.*;
public class exp1 extends Sprite
{
var directionX:Number = 5;
var directionY:Number = Math.random()*5;
public function exp1()
{
var loader:Loader = new Loader();
var request = new URLRequest("monkeyproj-1.jpg");
loader.load(request);
addChild(loader);
loader.x = 100;
loader.scaleY = 0.5;
var recA:Sprite = new Sprite;
recA.graphics.beginFill(0xFFF010);
recA.graphics.lineStyle(1);
recA.graphics.drawRect(40, 280, 50, 20);
addChild(recA);
recA.x = 300;
recA.y = 300;
recA.scaleX = 2;
recA.scaleY = 2;
recA.addEventListener(Event.ENTER_FRAME, moveRecA);
}
function moveRecA(e:Event){
e.currentTarget.y +=directionY;
e.currentTarget.x +=directionX;
}
}
}
I just tried the code and it seems to work fine. The only issue is that recA wasn't starting out as visible on stage. Try changing:
recA.graphics.drawRect(40, 280, 50, 20);
to:
recA.graphics.drawRect(0, 0, 50, 20);
That may or may not be what you want, but it makes the yellow box show up. Some of this depends on what dimensions you're deploying the swf with (i.e. the final stage size), so if that still doesn't work, try setting recA.x and recA.y to 0 as well.
精彩评论