There was a comment on how to load in an external image and then have the ability to manipulate the object – width / height / x position / y position / etc. If you ever want to retrieve any of the object’s parameters, you must first make sure the object is loaded in the object before you are trying to get the info.
package
{
import flash.display.Sprite;
import flash.display.Loader;
import flash.net.URLRequest;
import flash.events.Event;
import flash.events.MouseEvent;
import flash.events.IEventDispatcher;
public class ManipulateContentLoader extends Sprite
{
private var loader:Loader;
private var loaderHolder:Sprite;
public function ManipulateContentLoader()
{
init();
}
private function init():void
{
// load in the image
loader = new Loader();
loader.load(new URLRequest("http://manewc.com/projects/flash/i/gahlord.jpg"));
configureListeners(loader.contentLoaderInfo);
}
private function configureListeners(dispatcher:IEventDispatcher):void {
dispatcher.addEventListener(Event.COMPLETE, completeHandler);
}
private function completeHandler(e:Event):void
{
// bind the loader to a sprite
// 1. create the sprite
loaderHolder = new Sprite();
// 2. add the sprite
addChild ( loaderHolder );
// 3. bind image to the sprite
loaderHolder.addChild ( loader );
// 4. now manipulate
loaderHolder.width = 200;
loaderHolder.height = 200;
loaderHolder.x = 300;
loaderHolder.y = 200;
// .. even add an event
loaderHolder.addEventListener(MouseEvent.MOUSE_DOWN, MouseHandler);
}
private function MouseHandler(m:MouseEvent):void
{
trace (" == image clicked == ");
}
}
}
how to make the picture we loaded appear smooth like in AS2 we use forceSmoothing; but how about as3?
Hi Zain, I am truly not sure of this solution – but I know there is a draw() method of the bitmapData class that has a smoothing parameter. I’ll have to try it out when I get more time. I would say that the only issue will be a performance hit.
Hi admin,
Very nice example of how to use this!!
But trying to adapt this part for my own use I came up with some issues.
Let me first explain the thing that I want:
1) Using the MultipleFileSelection browser I want to let the user select one or more images.
2) After the selection I use a for each loop to iterate trough each file and call the loadImage function for each file.
3) After the loadImage function is called, the completeHandler has a different functionality. It makes a bitmap object and some other things. And after it is done it adds that bitmap object to an ArrayCollection. This arrayCollection is used as the dataprovider for my tilelist.
4) The tile list now shows the selected images.
This proces workes fine when selecting only one file, but when selecting more file (say 2) then the tile list shows two tile but the images are the same (last image which is selected).
And if I add a third one then there will be three tiles shown, displaying only the third image, three times.
None of the above happens if I select the files one by one.
I think I need some kind of other mechanism which waits until the first loadImage call is performed before it calls it again.
Or maybe some other kind of solution?
I’m planning to make a Picasa-a-like application, which lets the user select, edit and order a photo album, and after that it must be converted and uploaded to the server.
Any help would be very appreciated!
Thanks in advance,
Ramin