Link to home
Start Free TrialLog in
Avatar of Rouchie
RouchieFlag for United Kingdom of Great Britain and Northern Ireland

asked on

Setting _width after loadMovie

I have an empty movie clip on my main timeline that I'm using as a placeholder to load other swf's into.  After I load the swf into this placeholder and then try and set the width or height, it disappears!

Code used to load swf's in:

   placeHolder.loadMovie("some.swf"):
   placeHolder._width = 300;  // this makes it disappear

If I trace the width using:

   trace(placeHolder._width);

the trace window simply shows zero.

Can anyone help?  I'm pretty new to ActionScript so please include comments if you can!  I'm using Studio MX 2004 Pro.
ASKER CERTIFIED SOLUTION
Avatar of negatyve
negatyve

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Billystyx
Billystyx

just toadd, I find _xscale and _yscale easier to work with - but this is just an opinion:)
Avatar of Rouchie

ASKER

The movie that is being loaded is only 1.5kb, and for now is also running locally.  I'm currently working from a tutorial which reads and loads data based on an XML file, so it's a little tricky following the logic.  Earlier on in the code is where the check is performed to check that it's loaded.

Billystyx,
Using _xscale and _yscale does actually work perfectly, however, I will be importing SWF's of slightly different sizes and so would prefer pixel-perfect scaling to guarantee they fill the space provided.


Here are the full functions (all are in _root timeline frame 1):

this.onEnterFrame = function() { // check loading progress of movie URL read from XML file
filesize = placeHolder.getBytesTotal();
loaded = placeHolder.getBytesLoaded();
preloader._visible = true;
if (loaded != filesize) {
preloader.preload_bar._xscale = 100*loaded/filesize;
} else {
preloader._visible = false;  // hide preloader
if (placeHolder._alpha<100) {  // increase alpha of new movie to fade in
placeHolder._alpha += 10;
}
}
};


function showFirstPage() {   // this is called when the XML has successfully loaded
if (loaded == filesize) {
placeHolder._alpha = 0;
placeHolder.loadMovie(image[0], 1);
trace(placeHolder._width); // *** PROBLEM OCCURS HERE - This is returning zero ***
placeHolder._xscale = 50; // *** This works but might be too fiddly as all movies are slightly different sizes
desc_txt.text = description[0];
placeHolder_num();
}
}


I've put some more points on - hope you can help!
you need to put a moviecliploader in there, before you try and set the parametersa of the loaded movie.
take a look at
http://www.billystyx.co.uk/setups/fla8.zip

and see if that helps - it loads to levels, so you would set the width of the level(and x and y positions), but its not until loadInit that you try to set stuff in the new level.
Take a look anyway and ask me some qs if needed.

billystyx

SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Rouchie

ASKER

Taking your last comment into consideration, from this code:

function showFirstPage() {
      if (loaded == filesize) {
            placeHolder._alpha = 0;
            placeHolder.loadMovie(image[0], 1);
            placeHolder._width = 50; // DOES NOT WORK
            desc_txt.text = description[0];
            placeHolder_num();
      }
}

I removed the line that didn't work and placed it in the _root.onEnterFrame section, similar to that suggested by negatyve.  This now works, but I don't really undertand why!

This code is written as follows:

this.onEnterFrame = function() {
      filesize = placeHolder.getBytesTotal();
      loaded = placeHolder.getBytesLoaded();
      preloader._visible = true;
      if (loaded != filesize) {
            preloader.preload_bar._xscale = 100*loaded/filesize;
      } else {
            preloader._visible = false;
                  if (placeHolder._alpha<100) {
                        placeHolder._alpha += 10;
                  }
                  if (placeHolder._width != 0) {
                        placeHolder._width = 250;
                        placeHolder._height = 50;
                  }
      }
}

so I see it checks that the movie requested is completely loaded before setting _alpha and _width.  How come then that previous to this, I could use _xscale directly after the loadMovie command was used (which worked), but could not use _width?  Surely in theory you can set the width of something that can also be scaled??

By the way, if the above code is not reliable, please tell me, I need to try and learn the best way to do things with this language.
Avatar of Rouchie

ASKER

To expand on my question with more clarity, if I'm loading things INTO placeHolder, why can't I set the _width of placeHolder at any time like I seem to be able to do with _xscale and _alpha??
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial