Welcome, Guest
  • Author Topic: Flex Flash and stageScaleMode  (Read 4758 times)

    Jorge Solis

    • Global Moderator
    • Systems Administrator
    • *****
    • Posts: 14616
      • View Profile
    Flex Flash and stageScaleMode
    « on: 12/08/07, 17:16 »
    Following Flash 9 docs it's realtive easy to know that you need to access the stage property of a DisplayObject to manage the stageScaleMode


    //Timeline code
    var child:Sprite = new Sprite();
    child.name "stageMode"
    child.addEventListener(Event.ADDED_TO_STAGEstageListener); 
    	
    	
    	

    this.addChild(child);
    function 
    stageListener(evt:Event):void{
      var 
    t:Sprite Sprite(this.getChildByName("stageMode"))
       
    t.stage.scaleMode=StageScaleMode.SHOW_ALL;
    }


    But in Flex it becomes a little tricky because you can't add a Sprite to Stage, only objects that extends UIComponent, so you should do the same, but using some dummy component, say a Canvas


    //init function called from application creationComplete event
    function init():void{
       var 
    child:Sprite = new Canvas();
       
    child.name "stageMode"
       
    child.addEventListener(Event.ADDED_TO_STAGEstageListener); 
    	
    	
    	

       
    addChild(child);
    }
    private function 
    stageListener(evt:Event):void{
       var 
    child getChildByName("stageController")
       
    child.stage.scaleMode=StageScaleMode.SHOW_ALL;
    }


    Tryng to set inmediatly the scaleMode after the element is added to the displayList will trigger an error similar to this:

    TypeError: Error #1009: Cannot access a property or method of a null object reference.

    Jorge

    savneet

    • Seasoned Programmer
    • ***
    • Posts: 156
      • Yahoo Instant Messenger - savneets@yahoo.com
      • View Profile
      • Email
    Re: Flex Flash and stageScaleMode
    « Reply #1 on: 01/10/08, 23:03 »
    Hi,

    I have tried your code only i have change is instead of stageController i have given stageMode and there was no error in Flex.

    Thanks.