Anyways, today I was trying to see if I could create an object-spawner where objects would spawn when I tell them to. Unfortunately I haven't had much success with this. Here is the code I have been using:
var shape:Sprite = new Sprite();
var shape2:Sprite = new Sprite();
shape.graphics.lineStyle(1, 0x00ff00);
shape.graphics.beginFill(0xFFFA24);
shape.graphics.drawRect(0, 0, 10, 10);
shape.graphics.endFill();
shape.x = mouseX;
shape.y = mouseY;
addChild(shape);
shape2.graphics.lineStyle(1, 0x00ff00);
shape2.graphics.beginFill(0xFFFA24);
shape2.graphics.drawRect(0, 0, 10, 10);
shape2.graphics.endFill();
shape2.x = shape.x;
shape2.y = shape.y;
addEventListener(Event.ENTER_FRAME, follow);
function follow(e:Event):void
{
shape.x = mouseX;
shape.y = mouseY;
addChild(shape2);
}
Basically I'm trying to tell the code that an object ("shape") is following my mouse. That works fine. But I'm also trying to say that another object ("shape2") will spawn on the first object on every frame. The problem is that this only works on the first frame, then "shape2" will stop spawning. Anybody know how to fix this?
(I may refer to this topic in the future if/when I have other AS3 Questions. Alternatively other users can use this topic to ask their AS questions, because as far as I know we don't have an official topic.)








