08-25-2011 04:49 AM - edited 08-25-2011 06:48 AM
Hello there. I'm currently working on an app, which let user interact an object. When user click on the object,it'll move as a response. Here's my sample code
private var Ball:Image=new Image();
public function myApp()
{Ball.addEventListener(MouseEvent.CLICK,flyBall);
Ball.setImage("ball.png");
Ball.setPosition(0,0);
addChild(Ball);
}
private function flyBall(e:MouseEvent):void
{
Ball.removeEventListener(MouseEvent.CLICK,flyBall) ;
Ball.addEventListener(Event.ENTER_FRAME,moveBall);
}
private function moveBall(e:Event):void
{
Ball.x+=1;
}The code works for one image file. However, I wanted to replace ball.png with a .swf file, and so far i've tried loader, but loader doesn't allow me to set it's position. Is there any possible way to load one .swf file inside an image object? Or is there any other way to load .swf which enable me to move it around as in the code?
Solved! Go to Solution.
08-29-2011 05:51 PM
Hello Torres,
Can you clarify on your statement "loader doesn't allow me to set it's position." Since the Loader class is inherited from the parent DisplayObject, you can set it's position via x and y values.
http://help.adobe.com/en_US/FlashPlatform/referenc
Looking forward to your reply.
04-29-2012 06:39 AM
04-29-2012 06:44 AM
One more question, is there any function for .swf files which is equivalent to .bitmapdata of image file?
For example, I normally set an Image variable with
Image1.setImage((ImagePreLoad.getChildAt(0) as Bitmap).bitmapData); because if I use Image1.setImage("path") it'll set the image as well, but with a noticeable lag.
Now I got a loader variable, which essentially uses .load(UrlReq) to load a .swf object. I've initialized another pre set .swf variable which is running on the background. Is there any way to access it's .swf file similar to the bitmapdata of image file?