[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Setting _width after loadMovie

Posted on 2005-05-16
8
Medium Priority
?
481 Views
Last Modified: 2012-08-13
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.
0
Comment
Question by:Rouchie
  • 4
  • 3
8 Comments
 
LVL 27

Accepted Solution

by:
negatyve earned 300 total points
ID: 14011653
You have to wait until it's completely loaded:

var mc = placeHolder.createEmptyMovieClip("loader", 1);
mc._alpha = 0;
mc.loadMovie("some.swf"):
placeHolder.onEnterFrame = function()
{
      var l = this.loader.getBytesLoaded();
      var t = this.loader.getBytesTotal();
      if(l >= t && t != undefined){
            delete this.onEnterFrame;
            this.loader._width = 300;
            this.loader._alpha = 100;
      }
}
0
 
LVL 18

Expert Comment

by:Billystyx
ID: 14011756
just toadd, I find _xscale and _yscale easier to work with - but this is just an opinion:)
0
 
LVL 25

Author Comment

by:Rouchie
ID: 14016587
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!
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
LVL 18

Expert Comment

by:Billystyx
ID: 14016620
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

0
 
LVL 18

Assisted Solution

by:Billystyx
Billystyx earned 700 total points
ID: 14016676
either that, or directly after the loadMovie line , get rid of the rest of the code and place it on frame 4 (for example), then add this code (after the function)
onEnterFrame=function(){
if(placeholder._width>0){
gotoAndPlay(4);
}

billystyx
0
 
LVL 25

Author Comment

by:Rouchie
ID: 14017275
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.
0
 
LVL 25

Author Comment

by:Rouchie
ID: 14017340
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??
0
 
LVL 18

Assisted Solution

by:Billystyx
Billystyx earned 700 total points
ID: 14017545
The code is reliable - you can try the moviecliploader class as well (which is the newest way of doing this type of thing - but there seems to be places to use one and the other which work better for each.
loadMovie has the advantage of you being able to place by eye the loaded images into the movie, whereas it is easier to keep track of what is loaded and what isn't when working with levels rather than container clips(in the moviecliploader for instance), without having to add an extra instance of thew contaner to stage every time you want to load something different.
But in answe to your question, the alpha is easy enough to exp[lain - the alpha setting is being applied to the container clip which holds the loaded movie, so that property can be set any time.
The diference between x and yscale and width and height I am not so sure of - but it is good practise to make sure a clip is loaded before adjusting it anyway.
I agree though - surely xscale=50 of a clip 0 pixels wide will be 0 as will the width - I will look into this one myself - it seems odd:)


Billystyx
0

Featured Post

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This is a very simple example to help those of you who are still migrating from AS2 to AS3 understand the redesigned event model in AS3. In AS2.0, event functions (that is, the function to be performed when an event is fired) were stored as a pro…
I have been doing hardcore actionscripting for some time; and needless to say I have faced a lot of problems in just understanding others' code rather than understanding what the code executes. A programmer's life can become hell when there are a lo…
The goal of the tutorial is to teach the user how to use the auto adjust feature and what the different options do. When your video is not working right you can choose the auto adjust feature to help choose your settings.
The goal of the tutorial is to teach the user how to select which audio input to use. Once you have an audio input plugged into the laptop or computer, you will go into the audio input settings and choose which audio input you want to use.

834 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question