AS3 Change swf height with function - actionscript-3

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.

Related

Embed HTML to render a simple browser inside swf with StageWebView

I found a way to do this and it works when tested in Flash (Control+Enter).
But when I export movie clip as swf, the file size is only 2k and doesn't open with Acrobat Reader. This seems to be the best way for me, because then I want to insert the swf in a pdf file. My final intention is basically to have both a youtube playlist and a Facebook comment box embeded inside the pdf.
I'm using Flash CS6 and pasted this code:
import flash.display.MovieClip;
import flash.media.StageWebView;
import flash.geom.Rectangle;
import flash.events.KeyboardEvent;
import flash.ui.Keyboard;
import flash.desktop.NativeApplication;
//This will return the actual width value of our stage
var wView:int = stage.stageWidth;
//This will return the actual height value of our stage
var hView:int = stage.stageHeight;
//Create a new StageWebView object
var swv:StageWebView = new StageWebView();
//Set the size of StageWebView object created to match the screen size
swv.viewPort = new Rectangle(0,0,wView,hView);
//Load the Google Page
swv.loadURL("https://www.google.com/");
//Show the StageWebView Object
//If you want to hide it, set the stage property to null
swv.stage = this.stage;

keep object size and position unchanged in as3

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;

flash components and resizing

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.

Textbox disappears when I change width of initial sprite

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.

ActionScript Retrieving Width/Height Of Loader Image

i'm trying to access the width and height of an image that is added to the stage via a custom LoadImage class. the trace results are 0 even though the image displays correctly. what is the problem?
//frame script
var image:LoadImage = new LoadImage("myImage.jpeg");
addChild(image);
trace(image.width); //returns 0
//-------------------------
package
{
import flash.display.Sprite;
import flash.display.Loader;
import flash.net.URLRequest;
import flash.events.Event;
public class LoadImage extends Sprite
{
public function LoadImage(imageURL:String)
{
//Load Image
var imageLoader:Loader = new Loader();
imageLoader.contentLoaderInfo.addEventListener(Event.COMPLETE, imageHandler);
imageLoader.load(new URLRequest(imageURL));
}
private function imageHandler(evt:Event):void
{
addChild(evt.target.content);
}
}
}
If you're trying to access it right after you instantiate it, you don't have access to it's properties. You will have to make it event driven:
class LoadImage loads image
frame script listens for a complete event from LoadImage
LoadImage loads the image, once it has it's hands on it it dispatches the event
frame script works with the data
you need to make an event in LoadImage and once done in imageHandler, dispatch that. When you make your new LoadImage, set up the listener
var image:LoadImage = new LoadImage("myImage.jpeg");
image.addEventListener("complete", loadedImage); //or whatever you call the event
function loadedImage(evt:Event) {
addChild( evt.target );
trace(evt.target.content.width); //returns 0
}
you're trying to get the width and height before the image is completely loaded? see this question for more detail.