Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

how to set the height and width of loaded swf

New Here ,
Feb 24, 2013 Feb 24, 2013

hi

am loading swf into fla project

fla is 800 X 400

and the loaded swf is bigger than that

so how i can set the loaded swf in any size i wont and align

to the center of the right of the scene???

TOPICS
ActionScript
5.3K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Feb 24, 2013 Feb 24, 2013

If you want to scale loaded SWF proportionately and assuming your loader name loader here how you can do that:

addChild(loader.content);

if(width / height >= loader.content.width / loader.content.height) {

          loader.content.width = width;

          loader.content.scaleY = loader.content.scaleX;

          loader.content.y = (height - loader.content.height) * .5;

}

else {

          loader.content.height = height;

          loader.content.scaleX = loader.content.scaleX;

          loader.content.x = (width - loader.content.width) * .5;

}

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Feb 24, 2013 Feb 24, 2013

i got that error

TypeError: Error #2007: Parameter child must be non-null.

          at flash.display::DisplayObjectContainer/addChild()

          at Untitled_fla::MainTimeline/frame1()[Untitled_fla.MainTimeline::frame1:10]

and the loader name is

patloader

here is my code

var patloader:Loader=new Loader();

patloader.load(new URLRequest("patgame.swf"))

addChild(patloader.content);

if(width / height >= patloader.content.width / patloader.content.height) {

          patloader.content.width = width;

          patloader.content.scaleY = patloader.content.scaleX;

          patloader.content.y = (height - patloader.content.height) * .5;

}

else {

         patloader.content.height = height;

          patloader.content.scaleX = patloader.content.scaleX;

          patloader.content.x = (width - patloader.content.width) * .5;

}

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Feb 24, 2013 Feb 24, 2013

You have to wait until content is loaded and use this code only after that.

To wait - you need to add event listener to loaderInfo.

Here is Loader documentation that has examples:

http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/display/Loader.html

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Feb 24, 2013 Feb 24, 2013

im sorry can u give me the code of event listener

am kinda lost in that link u gave me

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Feb 24, 2013 Feb 24, 2013

is this what u mean ?

because i got the same error

the code

patloader.contentLoaderInfo.addEventListener(Event.COMPLETE, patloader_scale);

function patloader_scale(evt:Event):void {

 

                      if(width / height >= patloader.content.width / patloader.content.height) {

          patloader.content.width = width;

          patloader.content.scaleY = patloader.content.scaleX;

          patloader.content.y = (height - patloader.content.height) * .5;

}

else {

          patloader.content.height = height;

          patloader.content.scaleX = patloader.content.scaleX;

          patloader.content.x = (width - patloader.content.width) * .5;

}

          } 

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Feb 24, 2013 Feb 24, 2013

Loader.content is available on after load complete. So, you cannot add is as a child until then. Use addChild inside patloader_scale() function.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Feb 25, 2013 Feb 25, 2013

no errors

and the swf not loaded

all i got when testeing is a white screen

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Feb 28, 2013 Feb 28, 2013

can anyone help !!!

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Mar 02, 2013 Mar 02, 2013

How do you know that swf is not loaded?

It would be helpful if you posted code relevant to the problem.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Mar 02, 2013 Mar 02, 2013

i dont know all i got when testing is white screen and no error

here is the code

var patloader:Loader=new Loader();

patloader.load(new URLRequest("patgame.swf"))

patloader.contentLoaderInfo.addEventListener(Event.COMPLETE, patloader_scale);

function patloader_scale(evt:Event):void {

 

                      if(width / height >= patloader.content.width / patloader.content.height) {

          patloader.content.width = width;

          patloader.content.scaleY = patloader.content.scaleX;

          patloader.content.y = (height - patloader.content.height) * .5;

}

else {

          patloader.content.height = height;

          patloader.content.scaleX = patloader.content.scaleX;

          patloader.content.x = (width - patloader.content.width) * .5;

}

addChild(patloader.content);

          } 

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Mar 02, 2013 Mar 02, 2013

and thats when debug movie

Attempting to launch and connect to Player using URL C:\Users\Ayman\Desktop\tests\Untitled-1.swf

[SWF] C:\Users\user\Desktop\tests\Untitled-1.swf - 2708 bytes after decompression

[SWF] C:\Users\user\Desktop\tests\patgame.swf - 100969 bytes after decompression

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Mar 02, 2013 Mar 02, 2013

Never call load() on loader before adding event listeners, especially in the local environments. Load may occur intravenously, hence, complete event is not heard because it is dispatched BEFORE flash has a chance to add listener.

I suspect this is exactly what is happening in your case.

Change the code sequence and see what develops.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Mar 02, 2013 Mar 02, 2013

thats what u mean ?

var patloader:Loader=new Loader();

patloader.contentLoaderInfo.addEventListener(Event.COMPLETE, patloader_scale);

function patloader_scale(evt:Event):void

{

          if (width / height >= patloader.content.width / patloader.content.height)

          {

                    patloader.content.width = width;

                    patloader.content.scaleY = patloader.content.scaleX;

                    patloader.content.y = (height - patloader.content.height) * .5;

          }

          else

          {

                    patloader.content.height = height;

                    patloader.content.scaleX = patloader.content.scaleX;

                    patloader.content.x = (width - patloader.content.width) * .5;

          }

 

          patloader.load(new URLRequest("patgame.swf"));

          addChild(patloader.content);

}

if thats what u mean then its not work still white screen !!!

if its not plz what line of code u mean ? and where i put it ?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Mar 02, 2013 Mar 02, 2013

In this case it will not load at all.

call load() RIGHT AFTER you add event listener - not inside listener handler.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Mar 02, 2013 Mar 02, 2013

u meean between?

patloader.contentLoaderInfo.addEventListener(Event.COMPLETE, patloader_scale);

function patloader_scale(evt:Event):void

sorry if its annoying but i'm  a biggner 

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Mar 02, 2013 Mar 02, 2013

Yes, one can call it between.

var patloader:Loader=new Loader();

patloader.contentLoaderInfo.addEventListener(Event.COMPLETE, patloader_scale);

patloader.load(new URLRequest("patgame.swf"));

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Mar 03, 2013 Mar 03, 2013

still white screen ?

var patloader:Loader=new Loader();

patloader.contentLoaderInfo.addEventListener(Event.COMPLETE, patloader_scale);

patloader.load(new URLRequest("patgame.swf"));

function patloader_scale(evt:Event):void

{

          if (width / height >= patloader.content.width / patloader.content.height)

          {

                    patloader.content.width = width;

                    patloader.content.scaleY = patloader.content.scaleX;

                    patloader.content.y = (height - patloader.content.height) * .5;

          }

          else

          {

                    patloader.content.height = height;

                    patloader.content.scaleX = patloader.content.scaleX;

                    patloader.content.x = (width - patloader.content.width) * .5;

          }

          addChild(patloader.content);

}

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Mar 03, 2013 Mar 03, 2013

What is inside the swf you load? How does it look like when you open it separately?

Also what do you see when the following trace is injected?

function patloader_scale(evt:Event):void

{

trace(patloader.content.width, patloader.content.height);

          // the rest of the code

}

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Mar 03, 2013 Mar 03, 2013

the swf is a flash game

and the trace

818.3 601

btw the main fla is 800*400

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Mar 03, 2013 Mar 03, 2013

You did not answer the second question. What do you see when you open swf that you load independently - meaning by just double clicking on this swf?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Mar 03, 2013 Mar 03, 2013

the game

a screen with start buton when clicking it starts the game !!!

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Mar 03, 2013 Mar 03, 2013

no i didnt design it

i download it

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Mar 03, 2013 Mar 03, 2013

Well, if you downloaded - you may be out of luck. If this swf has special initialization routine that prevents it from using inside other swfs - you may not be able to use it. It also can have special API that makes it usable. Options are virtually unlimited and unless you know at least some of the swfs internal workings it may not be possible to utilize it.

As a developer I would definitely make sure that no one can use it.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Mar 03, 2013 Mar 03, 2013

Try this code and let me know if you see anything:

function patloader_scale(evt:Event):void

{

          patloader.content.width = 400;

          patloader.content.height = 400;

          addChild(patloader.content);

}

Also try this:

function patloader_scale(evt:Event):void

{

          patloader.width = 400;

          patloader.height = 400;

          addChild(patloader);

}

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines