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;
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 have a problem to maintain full screen of my flash player built in flex and as3 using osmf
I want to display panel bar right at the bottom of user's screen. This should work on all screen resolution. What I am doing currently is working fine to display video on full screen but issue is that its not aligning control panel of video accordingly.
What I have currently is this
stage.fullScreenSourceRect = new Rectangle(0, 0, fsvideoContainerW , fsvideoContainerH);
videoContainer.width = fsvideoContainerW;
videoContainer.height = fsvideoContainerH;
stage.scaleMode = StageScaleMode.EXACT_FIT;
stage.displayState = StageDisplayState.FULL_SCREEN;
Please help me on this.
I can't see code dedicated to the positioning controls in your code. Main idea when you create resizable components is to listen to the Event.RESIZE. Here is an small snippet how it works:
package {
import flash.display.Sprite;
import flash.display.StageAlign;
import flash.display.StageScaleMode;
import flash.events.Event;
public class StackOverflow extends Sprite {
private var _playerControls:VideoPlayerControls;
public function StackOverflow() {
addEventListener(Event.ADDED_TO_STAGE, onAdded);
}
private function onAdded(e:Event):void {
removeEventListener(Event.ADDED_TO_STAGE, onAdded);
stage.align = StageAlign.TOP_LEFT;
stage.scaleMode = StageScaleMode.NO_SCALE;
setup();
}
private function setup():void {
//Main event that will help you reposition and resize your UI components
stage.addEventListener(Event.RESIZE, onResize);
_playerControls = new VideoPlayerControls();
addChild(_playerControls)
}
private function onResize(e:Event):void {
_playerControls.updateWidth(stage.stageWidth);
_playerControls.y = stage.stageHeight - _playerControls.height;
}
}
}
import flash.display.Sprite;
internal class VideoPlayerControls extends Sprite {
public function VideoPlayerControls() {
this.graphics.beginFill(0x333333);
this.graphics.drawRect(0, 0, 100, 40);
}
internal function updateWidth(width:int):void {
//Do logic with reposition and resizing components
this.width = width;
}
}
Stage properties align and scaleMode should be set only once at startup of you video player.
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.
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.
I'm attempting to draw a text box on the screen. If I assign width and height to any value, as in the code below, I don't see anything drawn. Why is this? What is the use of width and height? Adobe's docs say it's the width/height of the sprite in pixels. Why would that occlude or prevent the drawing of a textbox or another box? I assumed the width/height would set the area that this sprite could be drawn upon, but based on this, I'm probably wrong.
Thanks in advance.
-Nick
package
{
import flash.display.Sprite;
import flash.events.Event;
import mx.core.* ;
import mx.collections.* ;
import flash.display.* ;
import flash.text.* ;
[SWF(width=1000,height=500)]
public class BareBones extends Sprite
{
public var backBuffer:BitmapData;
public var clearColor:uint = 0xFF0043AB;
public var display_txt:TextField;
public var i:uint = 0
public function BareBones()
{
addEventListener(Event.ENTER_FRAME, step);
width = 1000;
height = 500;
display_txt = new TextField();
display_txt.text = "Hello World!";
addChild(display_txt);
}
private function step(event:Event) : void
{
i++;
display_txt.text = i.toString();
}
}
}
When you set width and height in the constructor, you're actually affecting the scaleX and scaleY variables, which in turn affect root's transform.matrix.
In order to know how to set scaleX, Flash works off the content that is inside the clip. For example if you have a MovieClip with a 100x100 box in it, and you set width = 200, Flash will calculate that you mean scaleX = 2.
However you are setting width and height on a clip with nothing in it. The consequence is that scaleX and scaleY are both being set to 0.