A Flash Developer Resource Site

Results 1 to 6 of 6

Thread: [RESOLVED] Getting Width from a loaded SWF

  1. #1
    Mourning Morning. groupof1's Avatar
    Join Date
    Feb 2008
    Location
    Middle of somewhere
    Posts
    194

    resolved [RESOLVED] Getting Width from a loaded SWF

    I am having an issue with pulling width and height from an external swf.

    I can load it ok, and place it ok, but I want to shrink it when I place it and that is where the problem occurs. Here is the abridged code.
    The odd thing is that if I move the width and height lines inside the function, it works. Trouble is every time you click that tab the swf shrinks a little more.

    Code:
    //------------------Calling the external SWF and loading it-------------
    var myRequest:URLRequest = new URLRequest ("images/filter.swf");
    var myLoader:Loader = new Loader();
    myLoader.load(myRequest);
    
    //------calls Zoom Enhancement clip and sets size.------
    var zoomReq:URLRequest = new URLRequest ("images/zoom.swf");
    var zoomLoader:Loader = new Loader();
    zoomLoader.load (zoomReq);
    
     //----This is where the problem is
    var zoomClipWidth:Number = zoomLoader.content.width;
    var zoomClipHeight:Number = zoomLoader.content.height;
    
    
    //---------------- Tab Controls ---------------------
    
    tab5Switch.addEventListener (MouseEvent.MOUSE_DOWN, Frame5);
    
    
    
    function Frame5 (evt:MouseEvent):void {
    		this.tabs.gotoAndStop (5);
    		
    		if (zoomOn == 0) {
    		stage.addChildAt (zoomLoader, 1);
    		zoomLoader.x = 520;
    		zoomLoader.y = 75;
    		zoomLoader.width = zoomClipWidth * .9;
    		zoomLoader.height = zoomClipHeight * .9;
    		zoomOn = 1;
    		} 
    }
    Any help would be appreciated.
    What the world needs now is a nice hot bath.
    _________________________________________________
    Battles: Silverx2

  2. #2
    Lunatic
    Join Date
    Nov 2002
    Location
    AS3 Forum
    Posts
    342
    You are trying to define your variables with content that is not loaded yet.

    Just add an eventListener and define you variable once your swf is loaded.

    Code:
    //------------------Calling the external SWF and loading it-------------
    var myRequest:URLRequest = new URLRequest ("images/filter.swf");
    var myLoader:Loader = new Loader();
    myLoader.load(myRequest);
    
    //------calls Zoom Enhancement clip and sets size.------
    var zoomReq:URLRequest = new URLRequest ("images/zoom.swf");
    var zoomLoader:Loader = new Loader();
    zoomLoader.load (zoomReq);
    zoomLoader.contentLoaderInfo.addEventListener(Event.COMPLETE, zoomLoaded)
    
    function zoomLoaded (e:Event):void
    {
    
     //----This is where the problem is (not anymore)
    var zoomClipWidth:Number = zoomLoader.content.width;
    var zoomClipHeight:Number = zoomLoader.content.height;
    
    
    //---------------- Tab Controls ---------------------
    
    tab5Switch.addEventListener (MouseEvent.MOUSE_DOWN, Frame5);
    
    
    
    function Frame5 (evt:MouseEvent):void {
    		this.tabs.gotoAndStop (5);
    		
    		if (zoomOn == 0) {
    		stage.addChildAt (zoomLoader, 1);
    		zoomLoader.x = 520;
    		zoomLoader.y = 75;
    		zoomLoader.width = zoomClipWidth * .9;
    		zoomLoader.height = zoomClipHeight * .9;
    		zoomOn = 1;
    		} 
    }
    }
    Try that, lemme know how that goes for ya.

  3. #3
    Mourning Morning. groupof1's Avatar
    Join Date
    Feb 2008
    Location
    Middle of somewhere
    Posts
    194
    Forgive me, I am not a coder by nature and it's still early...

    Where do I set the variables? Inside the new zoomLoaded function and do I call the width/height there to use later on?
    I tried that but I get this: Access of undefined property zoomClipWidth: zoomLoader.width = zoomClipWidth;

    Here is how I changed the code.
    Code:
    // calls Zoom Enhancement clip and sets size.
    var zoomReq:URLRequest = new URLRequest ("images/zoom.swf");
    var zoomLoader:Loader = new Loader();
    zoomLoader.load (zoomReq);
    zoomLoader.contentLoaderInfo.addEventListener(Event.COMPLETE, zoomLoaded)
    
    function zoomLoaded (e:Event):void {
    	var zoomClipWidth:Number = zoomLoader.content.width  * .9;
    	var zoomClipHeight:Number = zoomLoader.content.height  * .9;
    	}
    -
    -
    -
    
    function Frame5 (evt:MouseEvent):void {
    		this.tabs.gotoAndStop (5);
    		
    		if (zoomOn == 0) {
    		stage.addChildAt (zoomLoader, 1);
    		zoomLoader.x = 520;
    		zoomLoader.y = 75;
    		zoomLoader.width = zoomClipWidth; //Access of undefined property zoomClipWidth (and height) happens here
    		zoomLoader.height = zoomClipHeight;
    		zoomOn = 1;
    		} 
    }
    I'm sure I am not adding 2 and 2 correctly here.
    What the world needs now is a nice hot bath.
    _________________________________________________
    Battles: Silverx2

  4. #4
    Mourning Morning. groupof1's Avatar
    Join Date
    Feb 2008
    Location
    Middle of somewhere
    Posts
    194
    Well what do you know. I figured it out. I was trying to declare and set the variables inside the function. I moved the var declaration outside of the function and set it inside the function.

    Thanks for your help.
    What the world needs now is a nice hot bath.
    _________________________________________________
    Battles: Silverx2

  5. #5
    Lunatic
    Join Date
    Nov 2002
    Location
    AS3 Forum
    Posts
    342
    Quote Originally Posted by groupof1 View Post
    Well what do you know. I figured it out. I was trying to declare and set the variables inside the function. I moved the var declaration outside of the function and set it inside the function.

    Thanks for your help.
    What did you do? Your post doesnt make sense.

    Please post your code so that somebody lurking around having a similar problem can fix it. And mark the thread 'resolved'.

  6. #6
    Mourning Morning. groupof1's Avatar
    Join Date
    Feb 2008
    Location
    Middle of somewhere
    Posts
    194
    Here is the final working code.

    Code:
    // calls Zoom Enhancement clip and sets size.
    var zoomReq:URLRequest = new URLRequest ("images/zoom.swf");
    var zoomLoader:Loader = new Loader();
    
    var zoomClipWidth:Number; //I was trying to declare these inside the zoomLoaded function
    var zoomClipHeight:Number; // Declare them first, then set them inside the function
    
    zoomLoader.load (zoomReq);
    zoomLoader.contentLoaderInfo.addEventListener(Event.COMPLETE, zoomLoaded)
    
    function zoomLoaded (e:Event):void {
    	zoomClipWidth = zoomLoader.content.width  * .9;
    	zoomClipHeight = zoomLoader.content.height  * .9;
    	}
    -
    -
    -
    tab5Switch.addEventListener (MouseEvent.MOUSE_DOWN, Frame5);
    
    
    function Frame5 (evt:MouseEvent):void {
    		this.tabs.gotoAndStop (5);
    		clipTest();
    		if (zoomOn == 0) {
    		stage.addChildAt (zoomLoader, 1);
    		zoomLoader.x = 520;
    		zoomLoader.y = 75;
    		zoomLoader.width = zoomClipWidth; 
    		zoomLoader.height = zoomClipHeight;
    		zoomOn = 1;
    		} 
    }
    This solves the issue of setting the width and height for the loaded swf and keeps it from shrinking more every time the tab is clicked where the swf is placed.
    What the world needs now is a nice hot bath.
    _________________________________________________
    Battles: Silverx2

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