PDA

View Full Version : Aligning imported png to stage?


maskedMan
04-15-2008, 11:37 PM
I've used JSFL to do the following:

create an empty movie clip
allow the user to import a png or other image file to the library
immediately put the imported image file in the empty movie clip

But as you can guess the image file is aligned with its top left corner in the mc's origin... but I need the image file to be aligned bottom center instead and I can't figure out how I'm supposed to make this happen. I saw some (very scant) documentation for the align method on http://dynamicflash.com/jsfl/ but it didn't show any examples of the method in use so I'm not clear on what you actually do with it.


Edit: here is some code based on what I found at http://fliiby.com/docs/uurvso3qpi.pdf


var BGFile = fl.browseForFileURL("select", "bgImage");
fl.getDocumentDOM().importFile(BGFile); //Successfully puts the graphic in the empty movie clip

fl.getDocumentDOM().align("bottom", true); //FAILS!
//Returns the following error message: "'align' requires a selection."

FlashWhip
04-17-2008, 04:56 AM
I believe that what might be happening is that the image you import is getting it's "bottom" edge aligned to the top-left corner point of the Stage. I just tried this myself, and that is what happens for me.

You might have to create your own alignment function. Should be too hard. You can just get the width and height of the stage. Then adjust the position of the image according to the width/height of that image and the width/height of the stage.

maskedMan
04-17-2008, 07:24 PM
Hey there,

Well the problem I had at the time wasn't that it got its bottom left edge aligned with anything. The script would hit that line of code and choke. I've found the answer, though! I had to figure out what it meant by "'align' requires a selection".


var Dom = fl.getDocumentDom();
var tl = Dom.getTimeline();
var currentlayer = tl.currentLayer;


Dom.importFile(BGFile);
Dom.selection = tl.layers[currentlayer].frames[0].elements // <-- got to set the selection before anything will happen.

Dom.align("bottom", true);