flex is not able to find the Screen class [duplicate] - actionscript-3

Can I get the obtain the size of the browser window in AS3?
The best method I've found is to get the size with Javascript and send it to Flash as a FlashVar. One limitation of this method is that it doesn't give the current size if the window is resized.
Is there a pure Flash way to do this?

If you embedd your swf with height: 100%; width:100% you could use stage.stageWidth and stage.stageHeight. If this is not the case you could implement a communication with JavaScript by using ExternalInterface.

It depends if you are trying to set your swf to fullscreen, or simply obtain window dimensions for some other purpose.
If you are doing fullscreen, you need to set your stageScaleMode to NO_SCALE, and embed your flash object into a div that has its height and width parameters set to 100%. To deal with resizing, your flash project needs a resize event listener (applied to the stage), and all display objects need to respond to that resize listener. Once your swf is resizing properly, you can, as already noted, use stage.stageHeight / stageWidth to retrieve exact dimensions internally.
If, on the other hand, you just want to obtain the dimesions of the window, you will need to use ExternalInterface to make a javascript call. jQuery has some nice tools for quickly obtaining screen dimentions. Then its just a matter of sending that data back into flash. Remember that javascript has a resize event, as well, and that you can use it to force state changes in flash.
You're correct in the initial piece of the sequence - sending flashvars in on load, but to respond to screen size changes, you will need to apply one of these techniques.
Good luck

Related

how to make existing flash file responsive

I have e learning books in flash file(.swf format) and i want to make it responsive.Can any one suggest a solution for this.please refer the link flash file
If you open the raw swf files in a browser, you can see that they are already responsive by default: http://rtpublishers.com/data/Hindi/Book1/pages/page1.swf
So, you need to change the way the Flash is embedded in your html page. Where you are using fixed 1300 x 900 pixels dimensions, use percentages instead.
In your Flash file, you can set the stage scaleMode = StageScaleMode.EXACT_FIT as explained here:
http://help.adobe.com/en_US/ActionScript/3.0_ProgrammingAS3/WS0D75B487-23B9-402d-A52D-CB3C4CEB9EE4.html
If there are parts of the Flash that you want to scale differently depending on stage size, you can listen to the stage RESIZE event, and respond accordingly.

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.

How to modify the size of Flash stage programmatically

Initially I set the stage width 500 and height 400. After make a file, now I want it to be 700*500 and I want to show all content in stage. How can I achieve this?
Any help will be appreciated.
If it's a website you're creating you can programmatically control its size via call through a class called ExternalInterface which in turn calls JavaScript-functions. JavaScript can then be used to resize the embedded flash object.
You can find another post about this here: How can I resize a swf during runtime to have the browser create html scrollbars?

Using img tag in an AS3 TextField without width and height attributes

I'm attempting to load HTML from the Shopify blog API into a TextField in Flash. The problem is that Shopify doesn't add width and height attributes to images that are in the blog posts. When I load these into Flash, the width and height of the image is ignored and the height of the TextField is incorrectl, which screws up my scrollbar among other things.
Is there any way to read the width and height of the images as they are loaded? I could possibly do this with PHP before it gets to Flash, but I'm not sure how.
Not sure about your original question about getting the image info in flash, but in PHP it wouldn't be much trouble, although it would slow down the process down somewhat.
Step 1: Setup a PHP proxy, which you call from your flash.
Step 2: In your PHP proxy, after grabbing the HTML, loop through all the img-tags. (You can do this easily, with e.g. PHP Simple HTML DOM)
Step 3: While looping, if the image dimensions are missing from the img-tag, download the image, check the image size and update the tag. (Also easy using PHP Simple HTML DOM)
Step 4: Echo the updated HTML to your flash movie.
If you use the BitmapData class you can get access to the width and height of images, along with other useful properties and methods.
if you load the image data (URLLoader in FlashPlayer or FileStream in AIR)
(FileStream would lets you do it synchronously)
with some effort you can parse the width and height of the image from the file HEADER synchronously.
if you want to display the image from the image data, throw it at loader.loadBytes for Adobe to decode it for you. sounds like you want it to show up in the htmlText though.
if you can manage to take a synchronous path to get all this data, your textfield can take into account the image height before the next frame so it won't look jittery.

How do you make a SWF resize inside a HTML page?

The stageHeight and stageWidth are read-write properties of the Stage class.
Is there any way to embed the swf so that when you set them to a different value, this is reflected in the HTML page? Possibly without calling a JS function via ExternalInterface to modify the embed's parameters?
The main idea is that I don't know what size my swf will be. I'm loading a video inside it and I want to resize the swf to match the size of the video.
We use
http://code.google.com/p/swfobject/
which allows for auto resizing in addition to some other nice features.
Your definitely going to need to call a JS function, the good news is it's really simple code, something like this:
function resizeIt(height)
{
document.getElementById("myDiv").height = height;
}
Using SWFObject in this case you can set the width and height to be 100%, so it'll resize with the containing DIV, so you're not modifying the embed paramerters, but just the css.
To my knowledge you can't do that. I can't actually fiddle around with it, 'cause i currently don't have access to flash.
It could work if you would insert the swf into a div, or whatever, that's "too big" for it in the first place, and then just try and resize it. What are you using to embed the swf, the basic thingie offered by the Flash IDE or something else, like swfobject?
I don't know, you might have to actually use ExternalInterface or something like that to get the job done. And if it's not terribly important to work the player into your web layout, i would just implement the whole thing in the flash movie.