.
Make a dynamic loader with AS3
In this Flash actionscript 3.0 tutorial you will see how to dynamically load image on to the stage give it properties, and adding an click event function to it.
In this tutorial we do not need to do anything on the stage, everything is in code, but remember to save your flash file in a folder and in the same folder keep the image you want to load, and name it the same as mine. "myimg.jpg".
The flash loader only supports .jpg .gif . png files and also loading other swf flash files.
Now go to the actionscript panel and type in or copy and past the following code.
The description of every codes line are inline with the code, with "//" in front of it, as comments in flash actionscript, so you can just copy it all and there should be no problem.
// First we define a variable of the type URLRequest and set it to the image url (in this case its in the same folder as the project file).
var imageRequest:URLRequest = new URLRequest("myimg.jpg");
// Now we define a loader to load in the image file.
var imageLoader:Loader = new Loader();
// This is where we set the loaders load property to the imageRequest we made in the first line).
imageLoader.load(imageRequest);
// Now adding the image to the stage.
addChild(imageLoader);
// Now we are able to do a lot with the image in the imageloader, we can set the position of the image x and y axis.
// We could even do opacity if we wanted.
imageLoader.x = 50;
imageLoader.y = 50;
// Now we will make the flash movie do something when someone clicks it, so we will add an eventlistener to the imageLoader.
// this will call the "doSomething" function that we write below.
imageLoader.addEventListener(MouseEvent.CLICK, doSomething);
// and here is the function, its quite simple, only thing it does is to make a URLRequest to my website
// then navigate to it when the image is clicked in the flash movie.
function doSomething(Event:MouseEvent):void
{
var _link:URLRequest = new URLRequest("http://www.blog.0tutor.com");
navigateToURL(_link);
}
Admin Bob says: 2008-10-25
SupeS says: 2008-10-24
nijo nicholast says: 2008-06-05

