A Flash Developer Resource Site

Results 1 to 2 of 2

Thread: position loader in center of scene aghhhh

  1. #1
    Junior Member
    Join Date
    Jun 2008
    Posts
    25

    position loader in center of scene aghhhh

    should be easy right? well none of my attempts work, they all appear in the same very edge of screen.

    each loader is created with a different sized image so the loader needs to be positioned dynamically to adjust for the varying hight / width of the loader object.

    i tried.

    Code:
    var myLoader:Loader = new Loader();
    		addChild(myLoader);
    		var url:URLRequest = new URLRequest(description);
    		myLoader.load(url);
    		myLoader.addEventListener( MouseEvent.CLICK, myLoaderClick );
    		function myLoaderClick(event:MouseEvent):void {
    
    		myLoader.unload();
    	
    		}
    		trace(stage.width, stage.stageWidth);
        	trace(stage.height, stage.stageHeight);
    		myLoader.x = (stage.stageWidth - myLoader.width) / 2;
    		myLoader.y = (stage.stageHeight - myLoader.height) / 2;
    		
    		
    		closebut.addEventListener(MouseEvent.MOUSE_DOWN, mouseDownHandler9);
    		function mouseDownHandler9(event:MouseEvent):void {
        
    		myLoader.unload();
    		}

  2. #2
    ___________________
    Join Date
    May 2004
    Posts
    3,174
    you're trying to position it before it has a height or width. you need to position it after it's loaded. try this:
    PHP Code:
    myLoader.contentLoaderInfo.addEventListener"complete", function(e){
        
    myLoader.= (stage.stageWidth myLoader.width) / 2;
        
    myLoader.= (stage.stageHeight myLoader.height) / 2;
    }); 

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