2

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()

shanethehat
  • 15,460
  • 11
  • 57
  • 87
Marcel
  • 21
  • 1

3 Answers3

2

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.

Cadin
  • 4,275
  • 1
  • 14
  • 22
0

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

Dmitry Sapelnikov
  • 1,129
  • 8
  • 16
  • Of course, the flash stage is not created according to the singleton design pattern. I used this word to emphasise that multiple stages are not supported. – Dmitry Sapelnikov Nov 09 '11 at 16:45
  • They are. Hence why its not a Singleton. One of my projects has 5 independent stages. – WORMSS Nov 10 '11 at 08:54
  • Could you provide a link to an example of multiple stages? Of course, my statement about multiple stages can be wrong, but I'd like to see a refutation. – Dmitry Sapelnikov Nov 10 '11 at 09:21
  • 1
    Thank you for the clarification. I haven't worked with AIR yet. But my answer was about flash content in a browser, not about AIR applications. – Dmitry Sapelnikov Nov 10 '11 at 10:32
  • My Apologies, In that case, it is not the "stage" width you need to change, it is the Element within the webpage you need to resize. External calls to Javascript will do this. Make sure stage.align is set to top right and stage.scale is set to no scale. **edit** seems Cadin beat me too it. Enjoy. – WORMSS Nov 10 '11 at 11:26
0

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.

James Tomasino
  • 3,520
  • 1
  • 20
  • 38