brymstone
06-21-2009, 02:19 PM
Create a new ActionScript 2 document in Flash for this tutorial.
What the code does
Creates an instance of the Loader component
Sets the component x, y, w, h, and border and background colours (useful for images with transparent backgrounds)
Loads image
Resizes image if larger than specified
Requirements
A copy of the Loader component in your library
Function example
imgBox("box1", 21, 200, 400, 400, 150, 0x707070, 0x2B2B22, "http://tinyurl.com/krcldt");
The code
Copy and paste the below code into your main timeline.
function imgBox(imgName:String, imgLyr:Number, imgX:Number, imgY:Number, imgW:Number, imgH:Number, imgBdrClr:Number, imgBgClr:Number, imgSrc:String):Void {
ldrObj = new Object();
ldrObj.complete = function(eventObject) {
// after loading, resize if too big
if (ldr._width>imgW && ldr._height>imgH) {
ldr._width = imgW;
ldr._height = imgH
}
};
// loader settings
var ldr = _root.createClassObject(mx.controls.Loader,imgName ,imgLyr,{_x:imgX, _y:imgY});
// loader style
ldr.setStyle("borderStyle","solid");
ldr.setStyle("borderColor",imgBdrClr);
ldr.setStyle("backgroundColor",imgBgClr);
ldr.contentPath = imgSrc;
ldr.scaleContent = false;
// loader listener
ldr.addEventListener("complete",ldrObj);
}
Load as many images as you want. One function call per image request.
Enjoy :cool:
What the code does
Creates an instance of the Loader component
Sets the component x, y, w, h, and border and background colours (useful for images with transparent backgrounds)
Loads image
Resizes image if larger than specified
Requirements
A copy of the Loader component in your library
Function example
imgBox("box1", 21, 200, 400, 400, 150, 0x707070, 0x2B2B22, "http://tinyurl.com/krcldt");
The code
Copy and paste the below code into your main timeline.
function imgBox(imgName:String, imgLyr:Number, imgX:Number, imgY:Number, imgW:Number, imgH:Number, imgBdrClr:Number, imgBgClr:Number, imgSrc:String):Void {
ldrObj = new Object();
ldrObj.complete = function(eventObject) {
// after loading, resize if too big
if (ldr._width>imgW && ldr._height>imgH) {
ldr._width = imgW;
ldr._height = imgH
}
};
// loader settings
var ldr = _root.createClassObject(mx.controls.Loader,imgName ,imgLyr,{_x:imgX, _y:imgY});
// loader style
ldr.setStyle("borderStyle","solid");
ldr.setStyle("borderColor",imgBdrClr);
ldr.setStyle("backgroundColor",imgBgClr);
ldr.contentPath = imgSrc;
ldr.scaleContent = false;
// loader listener
ldr.addEventListener("complete",ldrObj);
}
Load as many images as you want. One function call per image request.
Enjoy :cool: