Join 3,363 readers in helping fund MetaFilter (Hide)


Actionscript help, please!
December 7, 2007 8:19 AM   Subscribe

I'm trying to make a flash file scale to the width of a div. Friends, Romans, Actionscript People, how do I make this happen?

Simple diagram here. Basically, I want to know what actionscript I need to add to the file, and changes I might need to make to the swfobject info to make this happen.

The swf has a set height (which I want) and currently has a set width, (but I want to change that). Right now it stays the same size as the stage it was built on. I want it to expand to fit the div it's in. My actionscript is for poop, obviously. Thanks for your help.
posted by Mayor Curley to Computers & Internet (11 answers total) 1 user marked this as a favorite
 
I'm obviously not a flash expert.

But can't you just set the width attribute of the object and embed tags to 100%?
posted by bitdamaged at 8:22 AM on December 7, 2007


But can't you just set the width attribute of the object and embed tags to 100%?

I should have emphasized that it's placed with swfobject and that's how it has to be.
posted by Mayor Curley at 8:30 AM on December 7, 2007


Actually I don't think this is possible at all. And if it was possible, it wouldn't be possible with Actionscript.

You'd need to use Javascript in the browser, and the browser would need to support resizing Objects. I've never heard of a browser supporting that capability. And the fact that you're using swfobject means you won't know the exact DOM structure that will be generated, meaning it would be hard to figure find the object, since in theory it could be different on different browsers.
posted by delmoi at 8:37 AM on December 7, 2007


That said this guy got a SWF to resize. But you may not be able to use swfobject. I dunno.
posted by delmoi at 8:40 AM on December 7, 2007


I thought swfobject handles percentages fine? What happens if you just set the width to 100%?
How the Flash then fills the space depends upon the scale parameter.
posted by malevolent at 8:47 AM on December 7, 2007


(If you want to animate/control the size from ActionScript, I've found the best way to do that is to put a 100% width/height movie into a container div, then control the size of that div by calling ActionScript from JavaScript, e.g. with ExternalInterface.call . If you try to resize the Flash directly then it flickers/glitches in some browsers)
posted by malevolent at 8:55 AM on December 7, 2007


(Correction: calling JavaScript from ActionScript)
posted by malevolent at 8:56 AM on December 7, 2007


It does seem to be the display parameters. Here's the code below for swfobject:

var fo = new SWFObject("images/swf/h_main.swf", "mainarea", "100%", "283", "8", "#000000");
fo.addVariable("xmlfile","slidingXML");
fo.addVariable("menu","false");
fo.addVariable("align","left");
fo.addVariable("salign","lt");
fo.write("mainarea");

So if I change the 100% width to an exact number, it makes the swf that value (like 800 px if I ask for it). "100%" seems to make the movie scale to the exact height it was created at-- the allotted space for height is the same as the actual height of the piece. I just want it to spread out.
posted by Mayor Curley at 9:22 AM on December 7, 2007


seems to make the movie scale to the exact height it was created at

seems to make the movie scale to the exact height and width it was created at
posted by Mayor Curley at 9:28 AM on December 7, 2007


if you set the the SWFObject constructor's sizes to 100%, they should expand the stage to the size of the containing div. The div's dimensions should be explicitly set using css.

inside your flash movie, you'd use the Stage.align and Stage.scaleMode (stage.align and stage.scaleMode, in AS3) to stop the movie from scaling and then do something like this:

// as2
myClip._width = Stage.width;

// as3
myClip.width = stage.stageWidth;
posted by klanawa at 9:51 AM on December 7, 2007


"100%" seems to make the movie scale to the exact height it was created at-- the allotted space for height is the same as the actual height of the piece. I just want it to spread out.
I'm struggling to understand your description. Do you mean that when you change the width it doesn't enlarge the imagery in the Flash, and you want it to stretch? If so, change the scale param I mentioned; by default it ensure the entire stage stays visible, so it can't enlarge the movie unless both width and height are increased.
If you want to 'spread out' specific things within the Flash, so they're the same size but have more space inbetween, then you'll still want to embed at 100% width but stick with the default scale mode and use ActionScript to dynamically move things based on the stage's size.
posted by malevolent at 10:03 AM on December 7, 2007


« Older What is the best major to purs...   |  Where can I get sample data wi... Newer »
This thread is closed to new comments.