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

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/

Related

As3 change object width/height, then set new size scale as 1

I have an object manipulation function that(right now) manipulates the scale of the objects inside of an array to give real-time size changes in relation with each other.
What I would like to know is if there's a way to change an object's width/height(to fit the screen size since it's a mobile app) and then reset the scale so that the new width/height has a scaleX/scaleY value of 1.
The width/height are properties that directly influence the scale of a DisplayObject. You cannot resize it without affecting the scale.
You can however:
Draw the image as bitmap
Redraw it if it's a primitive
Put it in a holder
A little about every solution:
Drawing a DisplayObject (or any IBitmapDrawable) is done through creating a BitmapData and using a draw() call. The up-side is that it will be a bitmap and thus save some rendering time. The downside is that if it's a large image it will take memory (can be critical for mobile) and it won't have interactivity/animation unless you make a script that would read the animation.
If you're drawing the element though the Graphics class's API, you might just make something like a resize() method that you would call on window resize/flip-orientation. Just utilise the clear() method of the Graphics object and redraw the whole thing.
Lastly, probably your best pick. Resize your object. Make a new Sprite (I choose Sprite because it's interactive and you probably want that) and add the resized object to that newly made sprite while the Sprite is just added to the display list like you added the resized object before. If it's hard to understand, here's some code:
myResizeableObject.width = newWidth;
myResizeableObject.scaleY = newScaleY;
var holderSprite:Sprite = new Sprite();
myResizeableObject.parent.addChild(holderSprite); // if you don't have a specific place to add the myResizeableObject, don't use myResizeableObject.parent - it's ugly
holderSprite.addChild(myResizeableObject);
Hope that helps you!

Resize External swf

I'm writing an android app in flex as I need to display swf animations.
These swf files are larger than the mobile screen - they're advertisements used elsewhere.
I don't seem to be able to resize the loaded swf file. I've set height and width on the container, the loader everywhere I can think of and nothing changes the size of the swf.
It's frustrating, the swf is of a set size as they display full screen when used as advertisements, I just want to show a small preview within the app of what they will look like.
I'm beginning to think that it cannot be done? or am I missing something
I've seen similar questions asked here, but no answer that works for me.
There is only one stage, and the loaded swf probably resizes itself according to the stage dimensions, so it ignores the properties of the loader.
If you can modify the code of the loaded swf, you can:
either add it a method like setSize(width, height), and invoke it from the main swf:
yourSWFLoader.content.setSize(width, height);
or access to the loader dimensions from the loaded swf, using something like:
width = parent.parent.width;
height = parent.parent.height;
The second solution assumes the SWF is loaded from a trusted domain.

Changing size of an embedded flash swf in HTML

I have an HTML page with a background image.
I now want to add a flash (swf) to the corner of the page (a paper-like fold that can be peeled). The thing is the the flash is a small piece of UI (fold) that later opens to a larger view that covers more of the HTML (2 states that switch when clicking). I'm using swfObject.js and embedSwf:
swfobject.embedSWF("fold.swf", "pageFold", "auto", "400px", "9.0.0");
And my HTML is:
<div id="pageFold"></div>
I did several different tries with the width and height parameters, including having them fixed, but my problem is that the swf keeps on covering the HTML's backgound image, even when the swf is in it's smaller state (the folded corner)
Ideally, I would like to have one of the two:
Have a transparent background to the swf, so that I'll always see the HTML background image.
Dynamically change the size of the embedded swf - when it in the smaller state (a folded corner), keep the embedded object small. When the swf is clicked and therefore the flash UI is enlarged, give the embedded object some more space in the HTML.
Is any of these possible?
Any other options or ideas?
Thanks.
swfobject.embedSWF(swfUrlStr, replaceElemIdStr, widthStr, heightStr, swfVersionStr, xiSwfUrlStr, flashvarsObj, parObj, attObj, callbackFn)
you need set parObj and attObj as "wmode=transparent" (maybe {wmode:"transparent"})
Also you may need use
stage.scaleMode=StageScaleMode.NO_SCALE in your swf
Where callbackFn is a JavaScript function that has an event object as a parameter:
function callbackFn(e) { ... }
Properties of this event object are:
success, Boolean to indicate whether the creation of a Flash plugin-in <object> DOM was successful or not
id, String indicating the ID used in swfobject.registerObject
ref, HTML object element reference (returns undefined when success=false)
Use id parameter in callback function to manipulate your flash object - move, resize, etc

Changing the Stage size during runtime in AS3

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.

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.