I'm new to flex and I have a question concerning bitmapData and its width and height.
Normally you set up bitmapData like this in AS3:
var bd:BitmapData = new BitmapData(100, 100, true, 0x00000000);
var bm:Bitmap = new Bitmap(bd);
But in Flex embedding an an image works like this:
[Embed(source="../../../../../assets/sprites/asteroids/asteroid_32_full.gif")]
public static const Asteroid1:Class;
var imageBM:Bitmap = new Library.Asteroid1();
When using the bitmapData (e.g. imageBM.bitmapData) I don't have to set up width and height any more. Does the Flash player know the width and height of a bitmapData automatically even when NOT setting up the bitmapData's width and height? I'm totally unaware about this topic because I don't know whether the Flash player always knows the dimensions of a bitmapData. Could this cause problems when not setting up the dimensions of a bitmapData?
If you're generating a BitmapData object from scratch, you have to set the width and height.
If it's being generated automatically via image import, you don't. It's set under the covers by the image import process.
Related
I have my stage aligned to TOP_LEFT and scaled to StageScaleMode.NO_BORDER, the width and height of my SWF are : width = 1920 and height = 1080.
The thing is when my i change the SWF size to bigger (height/width) the movieClips on the stage scale up and that's a good thing for me, but when i reduce the size of my SWF to smaller values (smaller than the default size), the movieClips get reduced as well, aren't they supposed to stay the same, if not is there a way to make that happen ?
In fact the NO_BORDER scaleMode makes sure to not show the borders of the SWF and scale the center depending on the :
The ratios :
widthRatio = currentStageWidth/stageWidth
and
heightRatio = currentStageHeight/stageHeight.
The stageWidth and stageHeight are provided by AS3.
The currentStageWidth and currentStageHeight are supposed to be changing while resizing the browser window, the can be retrieved from the Flash Object (ie: $("#flashObjectId").width()).
Then we should compare the two ratios (widthRatio and heightRatio), the bigger one has the scale value for the stage and the other elements on the stage.
I do work on some already developped project.
myMovieClip has been scaled and is nested into many movieclips which may have been scaled themselves
When I trace his width and height, it does not give me the right width and size:
How can I get the absolute width and height ?
(the width and height it takes on the screen)
(a kind of localToGlobalWidth function)
regards
You can use the getBounds method of a display object to get the bounds (actual width/height and position) relative to whatever display object you pass to the method as an argument. (doucmentation)
myScaledObj.getBounds(stage); //would return a rectangle of where on the stage the display object is.
The width and height property of the returned rectangle would be what you'd use.
Do you know how many times it's been scaled, and by how much it's being scaled? In that case, you could trace the width * the scaling, for example:
mc1 has a width of 100, and is being scaled by 2:
mc1.scaleX = 2;
trace (mc1.width*2);
Extra information: if it's being scaled by a variable, replace 2 with the variable name.
This method should work even if it's being scaled multiple times, by using a variable to pile up the scaling:
var scaler1:int = 2;
var scaler2:int = 7;
var scalePiler:int = scaler1*scaler2;
mc1.scaleX = scalePiler;
trace (mc1.width*scalePiler);
Hope I helped and covered all possibilities, good luck with your program! ^^
I am having problem setting the stage height and width for the app i am developing.
I need to set the height and width as for the screen of the device it is on. So i do stage.fullScreenHeight and stage.fullScreenWidth.
But i just realized that the fullScreenHeight and width it is setting is the size for the stage inside flash pro cc under properties(the stage size).
And i am not able to make the stage width and height according to the phone's. Even if i do Capabilities.screenResolutionX; or stage.stageHeight. All of them set to either the size of the image, or the stage inside flash pro, but none is according to the device.
Edit:
E.g. var button = Button = new Button();
button.width = stage.stageWidth;
button.height = Button.width/stage.stageWidth * Button.height;
Try stage.scaleMode = StageScaleMode.NO_SCALE
or unchecking "full screen" checkbox in your Air settings
Documentation for the stageWidth property of the stage object states that:
If the value of the Stage.scaleMode property is set to
StageScaleMode.NO_SCALE when the user resizes the window, the Stage
content maintains its defined size while the stageWidth property
changes to reflect the new width size of the screen area occupied by
the SWF file. (In the other scale modes, the stageWidth property
always reflects the original width of the SWF file.)
But is there any way to affect that original width of the stage, without recompiling swf?
The stageWidth and stageHeight can not be set. They are based on the stagescalemode and the html container.
Or lets say there is a limited huge artboard what is the displayable area in flash(not regarding stageWidth).
If your swf has StageScaleMode.NO_SCALE its stageWidth will tell you the width of its container.And it will always fit its parent html element by showing you more or less of this artboard. But this can not directly be set by as3. To do so you need js.
If you have any StageScaleMode that scales the swf. Then its getting messy because that limited huge artboard gets streched and distrorted to meet the fittings.One pixel in as3 doesnt mean a pixel on screen anymore. But the part of that artbord that is visible will always be the same.
In the documentation for DisplayObject, it states that the width and height of the DisplayObject can not be changed if it is empty. Why is this restriction necessary? In every other framework I have used, you can resize containers that are empty. What is the reason for this madness?
In Flash, a DisplayObject is not solely a container for other DisplayObjects, though it can be. In Flash, a DisplayObject is just that, a displayable object... one that can be added to the DisplayList. What would be the original size of an empty sprite? 0x0? 1x1? The size is therefore determined by the contents being displayed.
That being said, you can change the scaleX and scaleY properties of an empty DisplayObject.
var c:Sprite = new Sprite();
c.scaleX = c.scaleY = 2;
c.graphics.beginFill(0);
c.graphics.drawRect(0, 0, 200, 80);
c.graphics.endFill();
addChild(c);
The sprite is 400x160 on the stage. :)
The reason you can't change an empty object's width and height is that they are ultimately derived properties. Along with the object's content, scaleX and scaleY are what really determines the object's size - width and height are really just convenient ways to adjust the scale.
In other words, when you change an object's width property, all Flash really does is to calculate what scaleX would be necessary to achieve the desired width, and then change scaleX to that value. When the object is empty, there is no scale value that would achieve any width except zero, so Flash ignores the request.