I am trying to create a chat program using Flash AS3, and so far, everything is going well, except for when the window is resized, my components are going to cut. I've used:
stage.align = "TL";
stage.scaleMode = "noScale";
import flash.display.StageAlign;
import flash.display.StageScaleMode;
...
public function InitializeChatProgram()
{
stage.scaleMode = StageScaleMode.NO_SCALE;
stage.align = StageAlign.TOP_LEFT;
}
In order to resize your objects properly, you need to rearrange them when the size of the window changes. For instance, if your chat component must be horizontally centered, your code would like :
stage.addEventListener(Event.RESIZE, resizeHandler);
private function resizeHandler(event:Event):void {
component.x = (stage.stageWidth+component.width) / 2;
}
If don't want to rearrange them and scale them proportionally, try to set the stage scale mode to other StageScaleMode values.
Related
I create a document which has 990px width and 40px height. I create a button and when I click the button I want to swf height grow up to 250px. Like this: http://demo.linkz.net/LinkZmasthead/turkcell/gece_kusu/default.html
I tried to change stage height but swf height doesn't grow up.
var mc:MovieClip;
mc = this["buton"];
mc.buttonMode = true;
mc.mouseChildren = false;
mc.addEventListener(MouseEvent.CLICK, clickHandler);
function clickHandler(e:MouseEvent):void {
// codes
}
How can I solve this issue?
Thank you
You can do this.
import flash.display.Stage;
import flash.display.StageAlign;
import flash.display.StageScaleMode;
import flash.events.Event;
swfStage.scaleMode = StageScaleMode.NO_SCALE;
swfStage.align = StageAlign.TOP_LEFT;
stage.addEventListener(Event.RESIZE, resizeYourStage);
function resizeYourStage(e:Event):void {
//resize code here
};
In your HTML add an onclick event to the button
<button type="button" onClick="StageResize.height = '250';">Resize</button>
Here is an example. You can right click on the page to inspect the swf size changes.
Note: In an HTML page hosting the SWF file, both the object and embed tags' height attributes must be set to a percentage not pixels.
I am beginner of as3. I am trying to keep object size and position static while the stage size changing. I want my objects size and position same in any condition of the stage. the stage can be full screen, can be resized by user, can be resized by device. i have added a ball on my screen and when i click the ball screen goes full screen. but in full screen mode my ball change its position and size. it gets bigger. how to keep the ball on the top left corner of the stage.
see the following screenshots and my code.
AS3 Code
package {
import flash.display.MovieClip;
import flash.display.SimpleButton;
import flash.events.MouseEvent;
import flash.display.*;
import flash.geom.Rectangle;
public class mainajaira extends MovieClip {
private var _ball=new ball();
private var stagewidht:Number=stage.stageWidth;
public function mainajaira() {
// constructor code
addChild(_ball);
_ball.x=0;
_ball.y=0;
trace(_ball.height + "." + "." + _ball.width);
trace("Stage Width:" + stagewidht);
trace("Ball x: " + _ball.x);
_ball.addEventListener(MouseEvent.CLICK, fullscreen)
}
private function fullscreen(e:MouseEvent):void{
if(stage.displayState==StageDisplayState.NORMAL){
stage.displayState=StageDisplayState.FULL_SCREEN}
else if (stage.displayState==StageDisplayState.FULL_SCREEN){
stage.displayState=StageDisplayState.NORMAL}
}
}
}
By default the stage will scale content (so your object dimensions are the same) instead of "expanding" to have extra area. You can adjust this with StageScaleMode. Your description sounds like you want NO_SCALE.
Typically:
stage.scaleMode = StageScaleMode.NO_SCALE;
stage.align = StageAlign.TOP_LEFT;
I am trying to find AS3 code for a MovieClip on my stage.
My stage resizes proportionally on different screens (different size monitors), but the MC gets too big for smaller screen laptops and some parts of it get cut off. Would appreciate for any help
You could restrict any scaling, and handle the sizing yourself:
stage.scaleMode = StageScaleMode.NO_SCALE;
stage.align = StageAlign.TOP_LEFT;
Have a look at the docs for the scale mode and align properties available.
Put this before anything else. This code find's the scale size from your original layout to the re-sized. (NOTE: It's best if you use this when Event.RESIZE is happening)
stage.scaleMode = StageScaleMode.NO_SCALE;
stage.align = StageAlign.TOP_LEFT;
var guiSize:Rectangle = new Rectangle(0, 0, 1024, 600); //original stage size, substitute this with your orginal size
var deviceSize:Rectangle = new Rectangle(0, 0,
Math.max(stage.fullScreenWidth, stage.fullScreenHeight),
Math.min(stage.fullScreenWidth, stage.fullScreenHeight));
var appScale:Number = 1;
if ((deviceSize.width/deviceSize.height) > (guiSize.width/guiSize.height)) {
appScale = deviceSize.height / guiSize.height;
}
else {
appScale = deviceSize.width / guiSize.width;
}
Than, use appScale to scale every MovieClip/Sprite you have, e.g. _mc.scaleX = _mc.scaleY = appScale.
Using this way, every time the stage get re-sized, the right and down border are moved. That means if you want your footer to be always 50px from bottom, you should use something like :
_footer.y = stage.stageHeight - (50 * appCale);
I have created a small tile 64x64 for testing my tile engine and it is added like so in the loop
var grass:Grass = new Grass();
grass.x = (x * TILE_SIZE);
grass.y = (y * TILE_SIZE);
grass.width = TILE_SIZE;
grass.height = TILE_SIZE;
container.addChild(grass);
public class Grass extends MovieClip {
public function Grass() {
// constructor code
this.width = 64;
this.height = 64;
}
}
If i trace out the .width and .scale of my object they match the code as 64x64 and a scale of 1. But when i print screen the screen in the debugger and measure in Photoshop they are 94x84 and I can find out where it is going wrong?
Anything I'm missing? Thanks
Assure stage scale mode is not scaling:
import flash.display.StageAlign;
import flash.display.StageScaleMode;
stage.scaleMode = StageScaleMode.NO_SCALE;
stage.align = StageAlign.TOP_LEFT;
Perhaps your debugger streches your flash video to fullscreen, which would stretch your grass object out. A screenshot would help.
Is this actionscript3? where is the declaration of the Grass class? there can be some error with it
Here's a very simple AS3 project consisting of one class which draws a rectangle. When I run it, the rectangle is clearly larger than 100x100 pixels. After pulling out my hair for a few hours I thought I'd ask: why?
Edit: I know that it isn't correct because, though I have my screen resolution set to 1280x800, if I set the width to 500 it takes up almost all of my screen.
package
{
import flash.display.Sprite;
import flash.events.Event;
public class Draw extends Sprite
{
private var screen:Sprite;
public function Draw():void
{
this.addEventListener(Event.ADDED_TO_STAGE, stageHandler);
}
private function stageHandler(e:Event):void{
screen = new Sprite();
screen.graphics.clear();
screen.graphics.beginFill(0x333333,.9);
screen.graphics.drawRect(0,0,100, 100);
screen.graphics.endFill();
addChild(screen);
trace(stage.width + "," + stage.height);
}
}
}
:
Somehow your scalemode settigns for your flash player are set in a strange mode from FlashBuilder.
Try setting
stage.scaleMode = StageScaleMode.NO_SCALE;
in your stageHandler function. You code has no errors. The problem is in your publish preview settings somewhere.