Jump to content
Search Community

scaling to stage width

wind_kind test
Moderator Tag

Recommended Posts



I have another couple of question about scaling. I have the box I'm scaling in a content sprite that scales itself as the movie dimensions change along with the browser window size.


Question 1. How do I scale the box to the stage width and when stage resizes the box resize with it, I thought it should do that anyway because it is inside a container that resizes the rest of the content but it just sticks to its set width.


Question2. This doesn't really have to do with tweenmax but hopefully someone can help anyway. I have an if statement that checks to see if any instance of one of the boxes are already loaded on the stage and if so tween it of stage and remove the child from the parent it was attached to. So obviously the statement doesn't work (I know how if statements work, sort of but I don't really know how what commands to use to get the desired result) Just trying my luck her if somone can help. If not the first question would be great if someone could help.


Thanx in advance


import flash.display.SpreadMethod;
import flash.display.Sprite;
import flash.display.StageAlign;
import flash.display.StageScaleMode;
import flash.events.ContextMenuEvent;
import flash.events.Event;
import flash.events.MouseEvent;
import flash.filters.BlurFilter;
import flash.filters.GlowFilter;
import flash.net.URLLoader;
import flash.ui.Mouse;
import gs.TweenMax;

public class main extends Sprite 
	//public static var origW:Number = 1024 //original stage width
	//public static var origH:Number = 768 //original stage height
	//public static var 

	//graphic resources
	private var bg:Sprite = new Sprite;
	private var cont:Sprite = new Sprite;
	private var art:Sprite = new Sprite;
	private var photo:Sprite = new Sprite;
	private var project:Sprite = new Sprite;
	var box:Sprite = new Sprite;
	var box1:Sprite = new Sprite;
	var box2:Sprite = new Sprite;

	//get the new stage height
	var sw:Number = stage.stageWidth;
	var sh:Number = stage.stageHeight;

	public function main ()
		//Tel the player not to scale the assets
		stage.scaleMode = StageScaleMode.NO_SCALE;

		//Tell the player to put co-ords 0,0 to the top left corner
		stage.align = StageAlign.TOP_LEFT;

		//Listen for resize events
		stage.addEventListener(Event.RESIZE, onResize);

		//Create and add body resource to the display list
		bg = new bg_mc();

		cont = new content();

		art = new art_mc();
		art.x = 94.2;
		art.y = 512.5;

		photo = new photo_mc();
		photo.x = 136.1;
		photo.y = 517.9;

		project = new project_mc();
		project.x = 150;
		project.y = 535;

		//Size everything after creation to insure the app is drawn 
		//properly the first time it is seen prior to any user initiated

		art.addEventListener(MouseEvent.CLICK, ClickListener)
		photo.addEventListener(MouseEvent.CLICK, ClickListener1)
		project.addEventListener(MouseEvent.CLICK, ClickListener2)

		//set button properties
		art.buttonMode = true;
		art.useHandCursor = true;
		photo.buttonMode = true;
		photo.useHandCursor = true;
		project.buttonMode = true;
		project.useHandCursor = true;

		//check ClickListener
		function ClickListener(event:MouseEvent):void
			art.mouseEnabled = false;
			photo.mouseEnabled = true;
			project.mouseEnabled = true;
			trace("button clicked:" + event.currentTarget);

			if (Boolean(cont.getChildByName('box1'))) {
				TweenMax.to(box1, 0.2, { x:500 } );
				if	(Boolean(cont.getChildByName('box2'))){
					TweenMax.to(box2, 0.2, { x:500 } );
				box.graphics.lineStyle(2, 0xffffff, 0.5, false, "none");
				box.graphics.beginFill(0x000000, 0.5);
				box.graphics.drawRect(0, 0, 10, 10);
					{ target:box, time:0.2, y:625 },
					{ target:box, time:0.5, scaleY:12 },
					{ target:box, time:1, x:35, scaleX:95 }


		function ClickListener1(event:MouseEvent):void
			art.mouseEnabled = true;
			photo.mouseEnabled = false;
			project.mouseEnabled = true;
			trace("button clicked:" + event.currentTarget);

			if (Boolean(cont.getChildByName('box'))) {
				TweenMax.to(box, 0.2, { x:500 } );
				if	(Boolean(cont.getChildByName('box2'))){
					TweenMax.to(box2, 0.2, { x:500 } );
				box1.graphics.lineStyle(2, 0xffffff, 0.5, false, "none");
				box1.graphics.beginFill(0x000000, 0.5);
				box1.graphics.drawRect(0, 0, 10, 10);
					{ target:box1, time:0.2, y:625 },
					{ target:box1, time:0.5, scaleY:12 },
					{ target:box1, time:1, x:35, scaleX:95 }
		function ClickListener2(event:MouseEvent):void
			art.mouseEnabled = true;
			photo.mouseEnabled = true;
			project.mouseEnabled = false;
			trace("button clicked:" + event.currentTarget);

			if (Boolean(cont.getChildByName('box'))) {
				TweenMax.to(box, 0.2, { x:500 } );
				if	(Boolean(cont.getChildByName('box1'))){
					TweenMax.to(box1, 0.2, { x:500 } );
				box2.graphics.lineStyle(2, 0xffffff, 0.5, false, "none");
				box2.graphics.beginFill(0x000000, 0.5);
				box2.graphics.drawRect(0, 0, 10, 10);
					{ target:box2, time:0.2, y:625 },
					{ target:box2, time:0.5, scaleY:12 },
					{ target:box2, time:1, x:35, scaleX:95 }

		//listening for stage resize
		public function onResize(event:Event):void
			sh = stage.stageHeight;
			sw = stage.stageWidth;

			//then update the children with this new size
			bg.height = sh;
			bg.width = sw;
			cont.height = sh;
			cont.width = sw;


Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
  • Create New...