Placing and sizing external images
Hi all,
Well, I've tried just about everything in terms of code and Google searches, but can't figure out how to get this AS script to work. I'm hoping you all can help.
For some background: I'm creating some e-learning modules using a client's existing Flash/AS/XML template. There is another separate file that is loading XML content and directing the "flow" or progression of the module. Basically, it is broken up into three parts:
1. Chapter = a selection made from a main menu (<chapter> in the XML) and is a large section; it is comprised of one to several "pages"
2. Page = sections within the chapters that users can progress to via navigation buttons; each page represents a separate Flash/SWF file with several clips (driven by audio clips played by another AS file from the XML direction). Also, each page has a certain AS file (only ONE) associated with it to either create interactivity, an activity, or text placement.
3. Clip = audio-driven parts of each page; represented within each 'page' FLA/SWF by keyframes.
These modules are being produced for two languages - thus the use of AS/XML to pull in text from two different files. We also have the need to pull in images using AS from the XML files. These images are essentially screenshots; some are large, some are small. Depending on text placement, we may want to resize images to make them fit within a certain space. Can you all suggest the best way to resize/scale these images dynamically. Basically, if the image's width is over 570 pixels or the height is greater than 550 pixels, I want to resize it so it fits within that 570x550 space. You can see the code that I tried (in "//") that didn't work. Feel free to comment on other aspects of the code.
Currently, as the code stands, the clips progress, and the images are placed correctly (centered in that 570x550 area), but obviously not sized.
If you need more to go off of, I'm not 100% sure I can provide it due to this being a proprietary template, but I'll do my best. Thanks in advance!
... (assume all variables are defined above the following code)
while (pageData['clip'+clipNum]) {
var t = MovieClip(parent.parent.parent).textBox();
imageURL = pageData['clip'+clipNum].@image;
//text loading
t.t.htmlText = pageData['clip'+clipNum];
t.t.width = 375;
t.t.autoSize = 'left';
t.alpha = 0;
t.x = 75;
t.y = 290-t.height/2;
t.name = 't'+clipNum;
//image loading
i = new Loader;
i.load(new URLRequest(imageURL));
i.contentLoaderInfo.addEventListener(Event.COMPLETE, iTransform);
i.name = 'i'+clipNum;
addChild(i);
this.addChild(t);
clipNum++;
}
function iTransform(event:Event):void
{
var imageLoader:Loader = Loader(event.target.loader);
var imageWidth:int = imageLoader.width;
var imageHeight:int = imageLoader.height;
imageLoader.alpha = 0;
//placement
imageLoader.x=700-(imageLoader.width/2);
imageLoader.y=290-(imageLoader.height/2);
//scaling
//if (imageWidth>570)
//{
// var imageNewWidth=1-((imageWidth-570)/570);
// imageLoader.scaleX=imageNewWidth;
// imageLoader.scaleY=imageNewWidth;
//}
}
function showItems() {
if (clipNum>=1) {
var tfadeIN:Tween = new Tween(this.getChildByName('t'+clipNum), "alpha", Regular.easeOut, 0, 1, 1, true);
tweenContainer.push(tfadeIN);
var ifadeIN:Tween = new Tween(getChildByName('i'+clipNum), "alpha", Regular.easeOut, 0, 1, 1, true);
tweenContainer.push(ifadeIN);
if (clipNum>1) {
var tfadeOUT:Tween = new Tween(this.getChildByName('t'+(clipNum-1)), "alpha", Regular.easeOut, 1, 0, 1, true);
tweenContainer.push(tfadeOUT);
var ifadeOUT:Tween = new Tween(getChildByName('i'+(clipNum-1)), "alpha", Regular.easeOut, 1, 0, 1, true);
tweenContainer.push(ifadeOUT);
}
clipNum++;
}
}
clipNum = 1;
showItems();