Hello,
I’ve been looking at the Loading Random Background Image Tutorial (http://http://www.kirupa.com/developer/mx/loadingrandombackground.htm )
and found it very informative and helpful, except for the fact that it does not seem to work with ActionScript 3.0 . It looks as if the problem lies in the “choice” property.
Could someone suggest a solution, or alternative method to have three random images?
Code as it is now:
choice = Math.round(Math.random()*3);
switch (choice) {
case 0 :
location.loadMovie(“quotation0.swf”);
break;
case 1 :
location.loadMovie(“quotation1.swf”);
break;
case 2 :
location.loadMovie(“quotation2.swf”);
break;
}
The first solution provided did not work, because “the method loadMovie is no longer supported”. I’m assuming this is because ActionScript 3.0 does not use that anymore?
The second solution looks really complicated… Could you provide some information about what I’m supposed to be changing to make this applicable to my movie? I’d rather not fumble through your code and possibly mess the whole thing up.
As you have already discovered yourself, the loadMovie method does not exist in AS3.
If you haven’t been working with AS3 before, it might take you some time to get this working in AS3.
I’ll tell you in short terms what you’ll have to do.
Generally, to load an external .swf, image, or video file, you use a Loader object.
This loader object will be replacing your current movieclip object called “location”.
So first you create an instance of the Loader class. Then you add it as a child of the stage to make it visible.
var location:Loader = new Loader();
addChild(location);
Now you have a Loader object on the stage. (Invisible so far, because it contains nothing)
Now you can access your Loader similarly to your previous location movieclip.
To load something into the Loader you use it’s *load *method.
You will also always have to create an URLRequest when loading an URL.
location.load(new URLRequest("mySwfUrl.swf"));
Now you can replace your AS2 loadMovie lines with this line.
The *switch *statement will look the same.
choice = Math.round(Math.random()*3);
switch (choice) {
case 0 :
location.load(new URLRequest("quotation0.swf"));
break;
case 1 :
location.load(new URLRequest("quotation1.swf"));
break;
case 2 :
location.load(new URLRequest("quotation2.swf"));
break;
}
Most likely, there will be other places in your code that needs to be translated to AS3.
Anyways, hope this helps as a start.
Be sure to read up on some AS3 basics to get a deeper understanding, it helps alot and makes it easier to learn more!