Marcel
Marcel

Reputation: 21

dynamic stage in actionscript 3

I was wondering if there is a way to make the actual stage dynamic to the content loaded in the flash file.

Firstly the method I am using is importing a external swf to the stage into a container called container. The main stage, lets call it index, is still on default size, and I want this to expand dynamically as content is loaded in.

page1 may be 900px width, page2 may be 500px width, and as I load the content the index stage should expand the width to that of the page loaded.

Some steps I have tried but did not work.

  1. if page1 button is pressed stage.stageHeight = 900; - not working (how do I set stage size in as3)
  2. made a movieclip in page 1 spanning the page size and called it p1_stage so I can reference the data from there. trace(container.p1_stage.height); gives this error:

TypeError: Error #1010: A term is undefined and has no properties.
at index_fla::MainTimeline/frame1()

Upvotes: 2

Views: 925

Answers (3)

James Tomasino
James Tomasino

Reputation: 3581

The stage is already fully dynamic and will adjust its stageHeight and stageWidth properties automatically with content. What you want is for the container (usually HTML) to update with these changes.

Add a listener to the RESIZE event of the stage and call your javascript via ExternalInterface. You can pass it along the new height & width values and resize the container that way.

Just a note: be careful of resizing the body tag. In certain browsers, that will reload your SWF.

Upvotes: 0

Cadin
Cadin

Reputation: 4629

swffit will do this (sort of).

It doesn't actually resize the stage, it's a Javascript that resizes the SWF in the browser. You would call it through ExternalInterface from within Flash with the size you need when the new content is loaded.

Upvotes: 2

Dmitry Sapelnikov
Dmitry Sapelnikov

Reputation: 1149

The stage is a singleton in flash. When you add your external swf via addChild(), its stage property changes to the stage of the parent display object. Moreover, you cannot change the stage width and height in actionscript code because they are read only parameters.

This problem was discussed here:

http://activeden.net/forums/thread/change-stage-width-height-just-with-actionscript/8854

http://forums.adobe.com/message/2705364

Upvotes: 0

Related Questions