Jump to content
GreenSock

Search In
  • More options...
Find results that contain...
Find results in...
ilvolgo

Event resize to SWFLoader content

Recommended Posts

Hello,

I have a simple (maybe?) problem, as long as I am a GS newbie, I hope you can help me solve it.

 

In my AS3 document class have a function:

 

public function nextModule(uri):void {

		while (_contentContainer.numChildren > 0) {

			_contentContainer.removeChildAt(0);

		}

		moduleLoader = new SWFLoader(uri,{
			 container: _contentContainer,
			 onComplete: moduleIsLoaded,
			 onProgress: moduleIsLoading,
			 onError: errorHandler,
			 estimatedBytes: 50000,
			 width: stage.stageWidth,
			 height: stage.stageHeight - 140,
			 scaleMode: 'proportionalInside',
			 autoDispose: true
		});

		moduleLoader.load();

	}

 

that loads external swf into my "_contentContainer" Sprite.

 

Then I wrote a simple event listener, "resizeHandler" to help me solve window resize issues:

 

public function resizeHandler(event:Event):void {

		_contentContainer.x=0;
		_contentContainer.y=0;				 

		_dock.x=0;
		_dock.y=0;

		logo_pop_small.x=stage.stageWidth/2-475;
		logo_pop_small.y=stage.stageHeight-logo_pop_small.height-40;

		menu_stripe.x=logo_pop_small.x-2157;
		menu_stripe.y=logo_pop_small.y+18;

		_menuContainer.x=logo_pop_small.x+160;
		_menuContainer.y=logo_pop_small.y+29;

		full_screen_toggler.x=logo_pop_small.x+935;
		full_screen_toggler.y=logo_pop_small.y+30;

		sound_control.x=logo_pop_small.x+843;
		sound_control.y=logo_pop_small.y+28;

	}

stage.addEventListener(Event.RESIZE, resizeHandler);
stage.dispatchEvent(new Event(Event.RESIZE));

 

My SWFLoader works fine and puts the content where it should be (as stated in "width", "height" and "scaleMode" properties of "moduleLoader"), but obviously, when I resize the browser window, my external swf loaded content is not repositioned :s

Is there any way to recall my SWFLoader repositioning propertier in my resize handler function?

 

Thank you in advance!

Link to comment
Share on other sites

I"m not sure if this answers your question, but you can access the vars object that you passed to your SWFLoader anytime like mySWFLoader.vars. So to get the height that you set, it'd be mySWFLoader.vars.height. If you CHANGE that value after the vars object is created, however, it has no effect. You can alter the width/height later using the SWFLoader's ContentDisplay's properties like fitWidth and fitHeight (if you don't want to stretch the content) or just width and height. like mySWFLoader.content.fitWidth = 500, etc.

 

Does that help?

Link to comment
Share on other sites

Ok, solved. It was a simple matter of logic, as witnessed by the vagueness of the question. Thanks anyway!

Link to comment
Share on other sites

  • 3 years later...

I know this was a while ago, but any chance you could post the solution? I need to resize the loaded swf to fit the stage, both at instatiation and upon browser resizing; it seems like you solved it, but I don't know how.

Link to comment
Share on other sites

HI ashiyawolf,

 

Not sure how to answer your question with more information than what has already been provided, other than adding that in your onresize handler you would set the SWFLoader's content's fitWidth and fitHeight properties to stage.stageWidth and stage.stageHeight

yourSWFLoader.content.fitWidth = stage.stageWidth;
yourSWFLoader.content.fitHeight = stage.stageHeight;

You can read about fitWidth and fitHeight in the ContentDisplay docs: http://greensock.com/asdocs/com/greensock/loading/display/ContentDisplay.html

 

Also, be sure that yourSWFLoader has a scaleMode set

 

var yourSWFLoader = new SWFLoader ("my.swf", {scaleMode:"proportionalInside"});

 

From the SWFLoader docs:

 

  • scaleMode : String - When a width and height are defined, the scaleMode controls how the loaded swf will be scaled to fit the area. The following values are recognized (you may use the com.greensock.layout.ScaleMode constants if you prefer):
    • "stretch" (the default) - The swf will fill the width/height exactly.
    • "proportionalInside" - The swf will be scaled proportionally to fit inside the area defined by the width/height
    • "proportionalOutside" - The swf will be scaled proportionally to completely fill the area, allowing portions of it to exceed the bounds defined by the width/height.
    • "widthOnly" - Only the width of the swf will be adjusted to fit.
    • "heightOnly" - Only the height of the swf will be adjusted to fit.
    • "none" - No scaling of the swf will occur.

If you need more help please provide a very simple example that illustrates how your existing code is set up.

Link to comment
Share on other sites

Thank you Carl for such a swift reply to a 3 year old post! That does help me, I can see now that you had given the answer in your post, but when ilvolgo replied I wasn't sure what had solved it for him. Now I think I understand!

 

The additional info you added now is very helpful and I think I can figure things out. I'm new to using Greensock and I'm evaluating it for our team. Sadly, I'm the most code-savvy of the designers. :(

 

I had also asked Michael B. a question about his 4-year old tutorial on Smart AS3 Video Loading, and he also replied right away. It's great to see that Greensock has such a supportive community!

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.
×