This content has been marked as final. Show 14 replies
Try to wait one frame before setting any data to your playList. Usually components have this bug.
It's not a bug, it's the 'nested assets problem'. The method isn't available yet, so the call has no meaning. Solution: you have to wait for the components properties and methods to load. And that's what the attached class does. Explanation: we use a setInterval to poll whether one of the methods of the component is available at which point you can safely assume that all properties and methods are available. You pass a reference (this) to the current object as a parameter to the setInterval to be able to call other methods in the class.
Kujanos, LuigiL THANK YOU SO MUCH!!!!!!!!!
I'm trying to understand this problem since 5 days!!
First I learned something about components and everything worked without classes.
But knowing the benefits of classes, I wanted to make my own mp3Player class and then i stuck into this problem.
And I just didn't want to do it without classes!
THANK YOU AGAIN!!!
You can't prove it won't happen.
One strange thing happens with the setInterval trick. When the instance of the mp3Player mc is called "mp3Player" it works, but if it has another name TWO columns are added, it seems the addColumn method is called twice... How is this possible?
It's even more confusing. If I put two instances of the mp3Player mc in the scene, the addColumn method will be called twice for each of them, but only as long as I don't name ONE of the instances "mp3Player". Then the method is called once.
This is some kind of strange magic to me ;-) I mean it's not the aim of classes, normally I don't know how the instance will be named...
Please clarify: (what instance)
>>When the instance of the mp3Player mc is called "mp3Player" it works
Show the code you are using.
yeah, it's a bit confusing, sorry. the code is the same as you posted.
I only mean, I have this movie clip in the library of my FLA callod "mp3Player" (it is linked to the mp3Player class).
When i drag an instance of it into the scene and name the instance of it "mp3Player" it works (one column "title" is added). when I name it "whatever" => two columns (title) are added. when i drag two instances of the mp3Player mc from the library to the scene and name only one of them "mp3Player" it works. Is none of them named like this again two columns are added...
Did you understand what I mean, now?
This is totally weird behaviour. You should be able to call the instances mc1 and mc2 and everything should work fine. T be sure: you are assigning instance names in the property inspector?
Are you on a Mac or PC/Windows?
yeah, its totally weird, if you like check it out with my sources from above.
I'm under windows and yes, when I drag the intstance of the mp3Player mc into the scene, I assign an Instance Name in the Property Inspector..
Well, I'm on a Mac. Everything works ok. I can name the instance(s) whatever I want except mp3Player which makes sense because the keyword this in the class then holds a reference to the mc mp3Player on the stage and that's not ok.
Maybe someone else can run a test on a windows machine (kglad?).
I cleared the scene and placed everything again, now I have the same situation as you. it works perfectly.
I think I had some problem with all the names: Linkage Identifier, symbol names, instance names, ...
I thought about this "nested assets problem", I mean that macromedia developers are aware of this and maybe there is some method for components which can tell you when an component is initialized completely and all methods are accessible. I only found UIObject.doLater and UIObject.load.
doLater: "Although any approach that delays access of the property will resolve this problem, the simplest and most direct solution is to use the doLater() method."
see: Components Language Reference > UIObject class > UIObject.doLater()
So it seems exactly their solution for this problem. I also thought that UIObject.load could help, but unfortunately when the mp3Player constructor is called both methods (doLater, load) are undefined so you would have to use setInterval to wait for them... and like this it makes no sense to call doLater, I can do everything within the interval.
It seems doLater works only if the script is attached to the component directly... am I right?
>>It seems doLater works only if the script is attached to the component directly... am I right?
Yes, with a minor detail: the component instance
yes of course i mean the instance. you have helped me quite a lot. i'll give it back to the forums when i'm not such an AS noob anymore ;-)