FORUMS: list search recent posts

dynamically created swf

COW Forums : Adobe Flash

<< PREVIOUS   •   FAQ   •   VIEW ALL   •   PRINT   •   NEXT >>
KB Brown
dynamically created swf
on Jun 30, 2010 at 6:38:57 pm

I have a 600x600 file, which I'd like to dynamically house and format images which fill the available space in one dimension or the other. The entire file area is covered by a movie clip solid black background. The image should load into this movieclip at 0,0 and depending on whether the w or h is equal to 600, then a solid 2px line should be placed either to the right of or below the image with a 2px offset. A certain number of pixels further from the image, image caption should be added with two types of text formatting in a non-standard font. I'd like to load the image path and caption data from an XML file into a parent file, and then pass that information to this swf file to create the formatted image. Here are my main sticking points.

1. determining whether has h or v orientation and passing the width and height of image to function which will create the appropriate line and text placement.

2. how to get the correct information passed into this file FROM THE PARENT FILE, ie, passing correct image from a menu item clicked in parent.

3. how to use embedded fonts to get the caption data to show in proper style. I know how to embed, but am having trouble getting my text to update dynamically, I just keep getting the holder text I had placed within this box.

I was hoping in this manner to have only one image template file into which images are loaded, rather than having to separately format all images. Then I can call this file from the main menu xml file, and pass along the appropriate image-specific info to this one file at the time of clicking on a menu item, to create a properly formatted image. Does this structure even make sense?

here would be a line of the xml (with some tag carats removed to make it display):

gallery title="Nature Photography" folder="images/" detailpath="swf/imagetemplate.swf">
image path="2.jpg" caption="Pretty House Los Angeles, CA"> /image>

the file retrieved would be detailpath, and the image used within the creation of the formatted image would be path. The caption would need to be formatted to make a color change between image title and location. Here is an example mockup of what I am seeking: - vertical orientation - horizontal orientation

I am pretty new to AS3, and know I'm asking a pretty big bunch of questions here... any and all assistance on even a portion (especially passing variables from parent file, that has me stumped!) will be greatly appreciated!

Return to posts index

KB Brown
Re: dynamically created swf
on Jul 2, 2010 at 5:47:18 pm

Okay, I realize I just dropped a lot of questions above and no code, so here's the code I have so far, in hope it will help me get a better response. I've tried to comment on the areas which are not working (text does not display, can't pull dimensions of image), but in addition, I'm still quite interested in being able to pass the correct image URL from the parent SWF file rather than getting it from the XML file (or alternately passing an ID tag somehow, so the SWF knows which item in XML list to grab). Thanks in advance for any assistance!



var galleryData:XML;

var galleryLoader:URLLoader = new URLLoader();
galleryLoader.addEventListener(Event.COMPLETE, onGalleryDataLoaded,
false, 0, true);

galleryLoader.load(new URLRequest("texter.xml"));

function onGalleryDataLoaded(evt:Event):void {
galleryData = new XML(;
// start checking if the movie is loaded
addEventListener(Event.ENTER_FRAME, onCheckLoaded,
false, 0, true);
galleryLoader.removeEventListener(Event.COMPLETE, onGalleryDataLoaded);

function onCheckLoaded(evt:Event):void {
if (root.loaderInfo.bytesTotal == root.loaderInfo.bytesLoaded){
removeEventListener(Event.ENTER_FRAME, onCheckLoaded);


var imgPath:String = galleryData.@folder + galleryData.image.@detail;

var imgBackground:MovieClip = new MovieClip();


var detailImage:Loader = new Loader();

detailImage.load(new URLRequest(imgPath));


detailImage.x = 0;
detailImage.y = 0;
imgBackground.buttonMode = true;

imgBackground.addEventListener(MouseEvent.CLICK, unloadImage);

//attempting to grab image dimensions, not working
imgBackground.detailImage.addEventListener(Event.COMPLETE, getDimensions);

function getDimensions(evt:Event):void {
var img:Bitmap = Bitmap(;
var imgWidth:int = img.width;
var imgHeight:int = img.height;, getDimensions);

//drawing the line beside the image
//temporary hard-coded values for image dimensions
var imgWidth:int = 450;
var imgHeight:int = 600;

var hOffset:int = imgWidth + 3;
var vOffset:int = imgHeight + 3;

var lineDrawing:MovieClip = new MovieClip();

if(imgWidth == 600) {,0x9a9345);,vOffset);,vOffset);
else if(imgHeight == 600) {,0x9a9345);, 0);, 600);

//not working, text does not display
//adding the text
var imgText:String = galleryData.image.@caption;

var textOffset:int = 20;
var textDrop:int = new int();

var imgCaption:TextField = new TextField();


if(imgWidth == 600) {
textDrop = imgHeight + textOffset;
imgBackground.imgCaption.x = textOffset;
imgBackground.imgCaption.y = textDrop;
else if(imgHeight == 600) {
textDrop = imgWidth + textOffset;
imgBackground.imgCaption.x = textDrop;
imgBackground.imgCaption.y = textOffset;

function unloadImage(e:MouseEvent):void {
//want to unload entire SWF each time button is clicked

Return to posts index

KB Brown
Re: dynamically created swf
on Jul 3, 2010 at 4:13:00 pm

Boy, the response time is very different in this thread from the film-related application threads I've been using here for years...

Well, in the meantime, managed to reroute my program architecture to negate the need for a button command that closes the swf file in which it sits (I'm still curious as to whether it can be done, if anyone knows, Google and my as3 books haven't yielded any answers beyond removeChild and loader objects in the underlying file, which is what I ended up using) and also the need to pass the correct image call from another file (again, interested in how this is done tho!). Only remaining questions there is whether simply removeChilding the loader and also the movieclip into which it was loaded will actually remove them from the memory rather than just the screen or do I need to do something else too?

I'm also still seeking an answer to grabbing image dimensions of a loaded image path without having to hard code them. I know it involves converting the image path string to a bitmap object so its height and width properties can be accessed, but not sure how to do this. Any suggestions? Pretty pretty please????

Return to posts index

<< PREVIOUS   •   VIEW ALL   •   PRINT   •   NEXT >>
© 2018 All Rights Reserved