How to create fixed size swf in pure AS3 only - apache-flex

I was wondering if there are anyways to get the fixed size swf file when I build my AS3 only project in Flex environment. I can't use scaleMode="noScale" since my swf is very small. I don't want it expand it to full browser winder either. Are there anyways to do it? Thanks for the help!

Your Application is sort of like a Canvas inside of the flash player. Thus, you can give it a fixed size (with the width and height attributes), but that will just reduce its size inside the flash player. I don't think you can mess with this in pure AS3 - you'd need to change the underlying HTML (although, you may be able to do this with ExternalInterface, which allows you to call javascript methods on the HTML page...).

Use metadata above the main class declaration
[SWF(width="400", height="125")]
public class MyAS3Project extends Sprite

Related

Differences between Image and BitmapImage with Flex?

In Image's asdoc, we can see :
Flex also includes the BitmapImage class. This class is used for embedding images into skins and FXG components
but we can also use Image in skins and use #Embed with Image...
Therefore, where and when should I use Image or BitmapImage please ?
Image is a skinnable class that wraps BitmapImage. As such BitmapImage is more lightweight, but Image has more features. So the question when to use which boils down to this:
if the features of BitmapImage suffice, use that; otherwise use Image. Especially in mobile environments try to favor the use of BitmapImage.
Now what features does Image add exactly?
Image extends SkinnableComponent: this means you can assign your images a skin with a border or a dropshadow or whatever you like consistently throughout your application.
It also provides a progress indicator which can be displayed while the image is loading.
One more feature is the possibility to queue the loading of multiple images.

Flex - Subclassing VBox in MXML to use as a base component, advice needed

I'd like to extend VBox to add some "defaults" and a bit of boilerplate-ish code (let's call it "VBoxSub" here), the idea being that "pages" in the application would extend this VBox subclass.
This seems to work fine except that the final classes extending "VBoxSub" don't inherit the width/height settings set in VBoxSub when in Flash Builder's design mode. When switching to design mode with the component empty, all it shows is a tiny plain box instead of a larger 1000x700 working area with the default VBox css background color. What's going on here? (Yeah I've tried refreshing/restarting design view.)
I'd like to have each of these components all be exactly the same size so that when laying out the UI I know exactly how much space I have to work with - preferably without having to copy/paste the width and height attributes into every darn mxml file (and having to worry about updating each one if the w/h ever change!). (Using Flash Builder 4, SDK 4.1)
I've tried doing this to get it to work, but still no good in Design View:
override protected function measure():void {
super.measure();
measuredWidth=1000;
measuredMinWidth=1000;
measuredHeight=700;
measuredMinHeight=700;
}
Do I really need to hard code width/height in every component "page" within the application?
Flash Builder doesn't execute Actionscript in design mode. Since the AS code doesn't get executed, the VBox doesn't get measured in design mode.
You need to use declarative MXML in such a situation.

Is there a way to use Flex 9-slice scaling at runtime?

I haven't been able to find an answer to this online. Is there a way to use 9-slice scaling with images loaded at runtime?
To clarify, let's say that I build an application that lets a user skin a button with whatever image they want. This would be an image that's not embedded with the swf. Is there a way to set that runtime image as a background and use 9-scaling?
Thanks!
You can specify a rectangle as the scale9grid of a movieClip that contains your image art.
http://www.sephiroth.it/tutorials/flashPHP/scale9/
Now, to use a MovieClip in Flex (it's a Flash thingy) you have to load it into a UIComponent:
http://cookbooks.adobe.com/post_You_wish_to_add_a_Sprite_or_MovieClip_to_a_Flex_ap-7142.html

Resize Sprite Flex/ActionScript

I am creating Sprite objects as simple shapes, and would like to know how to resize them dynamically.
my question:
How can I enable the Sprite to be re-sized on mouse drag(perhaps enabling a only a portion of the Sprite for this behavior)?
It might be important to note that I am using the Flex SDK, and therefore do not have full
access to the Flash libraries.
Thank you in advance.
You might want to check out the Flex Object Handles open source library. Check out the demo to see how it can be used to allow users to resize any object in a Flex app.
Doesn't the sprite always adapt itself to its contents to set its height and width? (like movieclips in as2). If you want to resize a sprite, I guess you'd have to draw something as background?
What do you mean by enabling a portion of the sprite to be re-sized?

Best Way to Animate Sprites in Flex

Is there a preferred way to handle animation when using Flex -- For instance, if I want to render a ball and bounce it around the screen?
If you're building a Flex application, you should use Flex's native Effect classes. They're probably already compiled into your app, since the core components use them, and you won't increase your SWF size with duplicate functionality like you would if you used another library. For simple animations, either mx.effects.AnimateProperty or mx.effects.Tween should work well.
If you're working on a regular ActionScript project (without the Flex framework), then I concur with the answer given by Marc Hughes. However, if that's the case, then please don't say you're using Flex because that implies that you're using the Flex framework and it can be very confusing. If you mean Flex Builder, then please use the full name to avoid potential misunderstandings.
You can't always use Flex's effect class with plain sprites. Certain effects expect your target object (the object to be tweened) to implement IUIComponent interface, while others don't. So you can either use mx.effects.Tween, or if you must use the one of the effects classses, you will need to coerce your sprite into a UIComponent.
Another option is to use one of the tween packages suggested above or roll your own with goasap!
goasap
I prefer to use a tweening library for things like this. Check these out:
Tweener
TweenLite / TweenMax
KitchenSync
I've had good luck actually using the first two, and have read great things about the last one.
You can use mx.effects.AnimateProperty even though your target is not a UIComponent.
If the tween you want to acheive is a simple one (Move, Resize, Fade etc) this saves you writing the boiler plate code that mx.effects.Tween requires.

Resources