
27-09-07, 09:44
|
|
Administrator
|
|
Join Date: Jul 2007
Location: Cesena
Posts: 4,535
Rep Power: 6
|
|
|
Tips abd Tricks Actionscript 3.0 - Loader.content
|
|
Greetings to all!
Developing with Flash CS3 and Actionscript 3.0, we often need to use small tricks which are often not easy to find. Every time that I will find myself in this situation, I will write an article.
The first article, as you will have understood from the title, regards the Loader class and its content property.
Let's see what is on about...
I take an example:
let's say that we have an SWF to load containing a TimeLine animation.
Once the SWF is completely loaded, we would like to interact with its TimeLine.
Imediatly, we would think to do the following way:
instanceNameLoader.content.play();
or
var clip:MovieClip=instanceNameLoader.content;
clip.gotoAndPlay(5);
In both case, Flash would return an error because the type of Loader's content (Loader.content) is not recognised by Flash at compile time.
At this point, we will need to use a trick:
I create a variable of 'universal' type, adding an asterisk.
The asterisk lets that variable hold any type of data.
var movie:*=instanceNameLoader.content.
Now, I create another variable, with a MovieClip data type, to which I will assign the value of the 'universal' variable (movie)
var clip:MovieClip=movie;
from now on, Flash recognised the Loader's content as a MovieClip with which I can interact as I wish.
clip.gotoAndPlay(5);
See you soon! |
__________________
I recommend: Essential Actionscript 3.0
- I do not reply technicians pvt messages. Open a thread !
- Non rispondo ai messaggi privati con domande tecniche. Apri una discussione sul forum !
|