Changing the Stage size during runtime in AS3 - actionscript-3

Can we change the stage size during runtime?
I need to change the size of the stage dynamically during the runtime when the swf receives a flashvar from the html page. Can this be done?

If you resize the <object> / <embed> elements in your HTML, that will resize the stage of the SWF.
The content of the SWF however will scale unless you specify that there will be no scaling within AS3:
stage.scaleMode = StageScaleMode.NO_SCALE;
It is also important to note when working with scalable SWFs that by default, the exported stage dimensions will always sit centred within the resized area, e.g.
I find it easier when everything is measured from the top-left of the resized area, which can be done by adding this as well:
stage.align = StageAlign.TOP_LEFT;

It's possible using flash.external.ExternalInterface
if (ExternalInterface.available) {
ExternalInterface.call('JSResizeBlockFunction');
}
JSResizeBlockFunction should be a javascript function defined on top level on the same page as running swf.
In this function you should change size of div in which <object>/<embed> is wrapped.
But your swf on page should have size in percents to receive RESIZE event.

Related

Flash dynamic stage size control

Did the stage can be changed dynamically in runtime? Means if the initial size is 400X300 and I want to change the size of the swf stage from html by 600x600?
You can't change the size of the stage from SWF e.g. by stage.stageWidth = 600; but you can tell containing HTML page to change width/height properties of embedded SWF then in your SWF you can respond to stage size change e.g.
stage.align = StageAlign.TOP_LEFT;
stage.scaleMode = StageScaleMode.NO_SCALE;
stage.addEventListener(Event.RESIZE, onStageResized, false, 0, true);
and update layout from there
You can change the size of the swf however you want in HTML. However, by default it will only scale the content, i.e., your code isn't aware of the external size of the swf.
If you set the Stage.scaleMode to StageScaleMode.NO_SCALE and the Stage.align property to StageAlign.TOP_LEFT, the stage will not scale but instead be set to the actual available dimensions.

FLVPlayBack not scaling to fullscreen

I'm trying to make an instance of FLVPlayBack run in fullscreen, without affecting the rest of the application.
According to stuff I've read, I have set the players scale mode so it will fit the window when its scaled up.
flvPlayer.scaleMode = "exactFit";
And in order to stop the stage from scaling up I've also set the stage's scale mode too.
stage.scaleMode = "noScale";
Then in order to try and control what the video player does when I click the fullscreen button, I also use the fullScreenTakeOver setting on the player.
If I set the code like to 'false'
flvPlayer.fullScreenTakeOver = false;
Then the whole interface becomes fullscreen, with the stage positioned in the centre of the window, I guess this is because I set the stage not to scale. The video stays its normal size and carries on doing what it was doing. Exiting fullscreen shrinks the stage back to normal.
If, on the other hand I set it to 'true'
flvPlayer.fullScreenTakeOver = true;
Then the video takes over the screen, but it doesn't scale up, instead it positions the video in the middle of the page, and the clickable areas of the controls move to where they would be if the video was full size, leaving my guessing where the buttons should be.
In both cases the video carries on running fine.
Can anyone help me with the right combination of settings? I want the application to stay its windowed size and the fly player to scale to fit fullscreen by itself.
Thanks.
There is a property in flvplayback named fullScreenTakeOver which is set by true by default. this will interfere with fullscreen really bad. if you want to apply fullscreen without changing logic of your stage you better set this as false after instantiation. this will decrease your troubles a lot
You'll want to set a few settings which some you've already done
stage.scaleMode = StageScaleMode.NO_SCALE;
stage.align = StageAlign.TOP_LEFT;
flvPlayer.fullScreenTakeOver = false;
Now when you enter full screen your application stuff will positioned top left. You will want to make an event listener for full screen mode.
stage.addEventListener(FullScreenEvent.FULL_SCREEN, fullScreenHandler);
In that event is where you will handle resizing and moving the video (Also hiding other objects on the stage if need be)
function fullScreenHandler(e:FullScreenEvent):void
{
if (stage.displayState == StageDisplayState.NORMAL)
{
// Setup NORMAL Layout
// resize and reposition the flvPlayer
}
else
{
// Setup FULL_SCREEN Layout
// move the flvPlayer to x:0 and y:0
// set the flvPlayer width and height to stage.stageWidth and stage.stageHeight
}
}

as3 | Flash | How Can I make fixed width-height when on full screen

After I export the .swf file in a certain size (1024*768) and then resize it manually (dragging the mouse to enlarge the screen) - everything stays in the same width and height.
After I export the .exe/.app file in a specific size (1024*768) and then resize it manually - everything scales (and I don't want that).
How can I define in the as3 settings to leave the width/height size static and not dynamic.
How can I tell the .exe file to get the full width and height of the current display?
I ask that because I want to have a full-size flash file that in the center there is the static sized stage.
To prevent scale use:
stage.scaleMode = StageScaleMode.NO_SCALE;
To enter fullscreen use:
stage.displayState = StageDisplayState.FULL_SCREEN;
Have a look at the docs
Take a look at the scaleMode property of stage. In your case it seems you would want to set it to StageScaleMode.NO_SCALE. The stageAlign property might be of interest too.
Read more in the livedocs.

Need to dynamically alter the main timeline display dimension to match a loaded 3D swf's dimension to keep source 3D properties?

The issue I'm having is that I have a main "wrapper" 100x100 (but it could be any size) - it's just there to hold and display whatever content, swf, gif, etc we may want to throw into it. As long as the loaded content doesn't have 3D animation like rotationY going on, it displays fine. But when it does, the 3D "anchor" properties (like projectionCenter) of the loaded swf inherit those of the main timeline (i.e. 100x100 (main) vs 728x90 (loaded)). If I change the dimension of the main "wrapper" in Flash IDE to match what's coming in - the 3D behaves fine, but I won't know what the dimensions of the content will be until it comes, so I need a way (if there is one) to dynamically alter the main "wrapper" or root display object through AS. Stuff like "this.width = loader.width" or "stage.width = loader.width" or "root.width = loader.width" etc doesn't work. Flex has the hBox and vBox - does AS have anything?
Use ExternalInterface to call a javascript function in the wrapper html, this will change the dimensions of the height/width of the enclosing div that wraps your .swf embd (Embed at width="100%" and height="100%") alternatively use swfobject to get a handle on the embedded object and change the height/width properties to match.
Then you can attach a Event.RESIZE listener and reposition your elements when the swf has been resized to fit the contents.
This is an example (Though just the height of the swf is changing) http://www.markgriffo.com/scrollTest/

dimensions of loaded swf's stage

Here's the situation - I've got a shell that loads an external .swf. Now, that .swf is 800x600, but it's an animation piece, and there are elements that extends off the stage. When I load the .swf into the shell and call its width attribute, it returns 1200 - because it's including the elements that break out of the stage.
This isn't what I want - ideally, there would be two properties, one to return the 'calculated width' and one to return the 'default width'. Do these properties exist, and if not, what's the best workaround?
The width and height of the loaded SWF as defined by the FLA it was created with can be found in the Loader object in which you've loaded the SWF into.
swfLoader.contentLoaderInfo.width
swfLoader.contentLoaderInfo.height
This will always show you the dimensions as defined in the FLA properties. It makes no difference if any images, MovieClips, or what have you extend off the stage.
The stage.stageWidth and stage.stageHeight properties will always return the width of the stage, the stage is always the top most SWF. In other words, it will always represent the dimensions of the shell's stage. There is only ever one stage in a Flash application.
Mark is very likely right that the content loader info object will contain the correct width and height. I've never checked myself so I can't guarantee it. The docs say 'nominal' and contrast it with 'actual' so it seems reasonable.
There are a couple of other options. You can mask the external swf. Create a mask that is the size of the stage and put all content underneath it. Another idea is to create a movieclip based on a rectangular shape set it's alpha to 0 place it at x:0, y:0 and match it's width and height to stage. Give it an instance name and then when it is loaded use that value for the size.