A Flash Developer Resource Site

Results 1 to 4 of 4

Thread: Align objects when ResizeStage problems

  1. #1
    Junior Member
    Join Date
    Nov 2009
    Posts
    16

    Align objects when ResizeStage problems

    I'm trying to align an object on the stage "mymenu" when the browser resizes.
    If I write a function to do that inside the flash document, it works properly but now I'm trying to do it from the main class that it called by the main swf.

    Code:
    private var stageW:uint = stage.stageWidth;
    private var stageH: uint=stage.stageHeight;
    ///////////////////////////
    public function main() {
         setsizeStage();
      }
    ///////////////////////////
    private function setsizeStage():void {
       stage.scaleMode = StageScaleMode.NO_SCALE;
       stage.align = StageAlign.TOP_LEFT;
       stage.addEventListener(Event.RESIZE, resizeStage);
       stage.dispatchEvent(new Event(Event.RESIZE));
      }
    ///////////////////////////
    private function resizeStage(event:Event):void {
       stageW = stage.stageWidth;
       stageH = stage.stageHeight;
       var menudestinyX:uint= (stageW/2)-100;
       var menudestinyY:uint= 100;
       trace(stageW+" "+stageH);
       TweenLite.to(mymenu, 1, {x:menudestinyX,y:menudestinyY, ease:Expo.easeOut});
      }
    The output says me that "mymenu" property is not defined but the object is defined and added to de displaylist.

    What could be the problem?

  2. #2
    rabid_Delineator AttackRabbit's Avatar
    Join Date
    Dec 2003
    Location
    Orlando, Florida
    Posts
    481
    is it added to the display list yet ? When does it get added ? I dont see it being declared in main.

  3. #3
    Junior Member
    Join Date
    Nov 2009
    Posts
    16

    Align objects when ResizeStage problems RESOLVE

    here the solution:
    Code:
    package {
    	import flash.display.StageAlign;
    	import flash.display.StageScaleMode;
    	import flash.display.MovieClip;
    	import flash.net.URLLoader;
    	import flash.net.URLRequest;
    	import flash.events.Event;
    	import clases.menu.menu;
    	import clases.menu.submenu;
    	import com.greensock.*;
    	import com.greensock.easing.*;
    	import com.greensock.plugins.*;
    	////////////////////////////////////////////////////////////////////////////////////////////////
    	public class main extends MovieClip {
    		////////////////////////////////////////
    		private var stageW:uint = stage.stageWidth;
    		private var stageH: uint=stage.stageHeight;
    		private var subject:MovieClip;
    		////////////////////////////////////////
    		public function main() {
    			var xml:XML;
    			var url:URLRequest = new URLRequest("secciones.xml");
    			var loader:URLLoader = new URLLoader();
    			loader.load(url);
    			loader.addEventListener(Event.COMPLETE, createmenu);
    			setsizeStage();
    		}
    	////////////////////////////////////////////////////////////////////////////////////////////////
    		private function setsizeStage():void {
    			stage.scaleMode = StageScaleMode.NO_SCALE;
    			stage.align = StageAlign.TOP_LEFT;
    			stage.addEventListener(Event.RESIZE, resizeStage);
    			stage.dispatchEvent(new Event(Event.RESIZE));
    	////////////////////////////////////////////////////////////////////////////////////////////////
    		}
    	
    		private function createmenu(event:Event):void {
    			var xmlData= new XML(event.target.data);
    			var mymenu:menu = new menu(xmlData);
    			addChild(mymenu);
    			mymenu.x = (stageW/2)-200;
    			mymenu.y = 100;
    	////////////////////////////////////////////////////////////////////////////////////////////////
    		}
    		private function resizeStage(event:Event):void {
    			this.subject=this;
    			stageW = stage.stageWidth;
    			stageH = stage.stageHeight;
    			var menudestinyX:uint= (stageW/2)-100;
    			var menudestinyY:uint= 100;
    			trace(stageW+" "+stageH);
    			TweenLite.to(subject, 1, {x:menudestinyX,y:menudestinyY, ease:Expo.easeOut});
    		}
    	}
    }
    I just changed the following line:
    this.subject=this;

    Thanks to creacionro

  4. #4
    Junior Member
    Join Date
    Nov 2009
    Posts
    16

    resolved More accurate solution

    in the upper script, what you are moving is the [main object]. To relocate "mymenu" you have to remove the following line in the resizeStage() method:
    this.subject=this;
    and put this line inside the createmenu() method:
    subject=mymenu;

    the variable "var subject:MovieClip" is declare at the begining and after the createmenu() method is dispatch you can pass the variable "mymenu" to the resizeStage() method:
    TweenLite.to(subject, 1, {x:menudestinyX,y:menudestinyY, ease:Expo.easeOut});

    If you want to relocate more elements, you have to create a new variable like "subject2" and everytime you create a new object through the constructor, relate the both objets:
    mynewobject2 = subject2
    and add a new tween in the resizeStage() method:
    TweenLite.to(subject2, 1, {x:anydestinyX,y:anydestinyY, ease:Expo.easeOut});

    Probably there is a better way thus, if someone know how to do this kind of rutine is really wellcome.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center