I can’t seem to figure out how to target an mc properly after loadMovie.
I have a swf where an mc is copied 15 times (so a 4*4 grid is formed) like this:
Movieclip.prototype.duplicateMC = function(){
amount = 16
x = 1;
y = 0;
for (i=1; i<amount; i++){
//trace("x:" + x + " y: " + y);
duplicateMovieClip(this, "copy"+i, i);
if (i%4 == 0) {
x = 0;
y += 1;
}
_root["copy"+i]._x += 50*x;
_root["copy"+i]._y += 50*y;
x++;
}
}
this.onLoad = function(){
_root.original.duplicateMC();
}
This works fine. However, when I load it into another movie with loadMovie, it doesn’t work anymore because of the _root that I use.
I thought that using _parent[“copy”+i]._x += 50*x; would do the trick, but it doesn’t…
Who can help me out on the proper notation for this??
However, if I would target the container mc directly, my original movie wouldn’t work as a standalone movie anymore, am I right?
Also I’m just wondering: what would be the benefit of using attachMovie instead of placing one instance on stage and copy that with duplicateMovieClip?
Problem 1) Since you are loading this in… the _root is no longer the _root… it is now a sub timeline of the _root timeline in the main movie you are loading into.
_root[“copy”+i]._x += 50*x;
Since you are targeting a movie clip to be affected by this prototype, this and _parent won’t do exactly what you want. So what you need to do is combine them into this._parent
Same goes with
_root.original.duplicateMC();
Except this is locating the target clip, all you have to do is just remove the _root part.
Problem 2) Not really a problem, more like useless code. You don’t need an onLoad on frame when the actions are supposed to load when the frame loads. By putting them just on the frame thy are told to load when the frame loads… so there is no point to an onLoad for a frame.
[AS]Movieclip.prototype.duplicateMC = function() {
amount = 16;
x = 1;
y = 0;
for (i=1; i<amount; i++) {
//trace(“x:” + x + " y: " + y);
this.duplicateMovieClip(“copy”+i, i);
if (i%4 == 0) {
x = 0;
y += 1;
}
this._parent[“copy”+i]._x += 50x;
this._parent[“copy”+i]._y += 50y;
x++;
}
};
original.duplicateMC();[/AS]
NOTE: DO NOT use the above code. It is pointless to write it out like that if you dont need to. Obfuscating (compressing the code) is a pain to read and can actually slow down the performance of your code. I did this out of sheer bordom, I just figured if I posted it, then maybe you may learn a trick or two from it
And don’t worry about learning obfuscated script, unless you are going to be in a situation where you have to code something in as little lines as humanly possible, then you don’t need it. It just makes things a pain to read and edit
I posted that method here because I did get bored and I wanted to see how many lines I could get it down to
Lost in beta said
What I did was assign the duplicate movie clip as a variable called “mc” That way you can reference the duplicated movie clip through “mc”
I am wondering how you “reference” a movie clip so that it is recognized as “mc” or whatever you choose to call it?
Lost in beta… you’ve been seeing me trying to do this for the last few weeks and I think your aware of my lack of knowlede in scripting beyond lodmovie in this movie clip and button commands. I was wondering if for the next 15 minutes you could help me get this nightmare of a menu figured out in a simplified way.
If you can help me understand what it is I have to do to get what I could go to sleep at night with my girlfriend instead of leaving her angry at me for staying up all hours of the night.
But I am going to try and rewrite something. That Flash 4 syntax gives me the biggest friggin headache… I got nuts flipping from frame to frame from timeline to timeline just to figure out what does what in that script. It can be so much easier in MX.
I really appretiate your help.
I’ve been trying to learn actionscript through trial error, copying pasting and applying the effects I see into my sites. I have done well up until this point and I have found things I don’t understand at all like
prototype
pathing _root _parent (i understand the concept but not the application)
how to apply different button commands to duplicate movieclips
so is the other thread enough for us to start discussing what is to be done or would you need me to explain step by step what I am aiming for so we figure somthing out… I am under the impression from your last post that your tackling this right away but I am not sure and want to contribute if i can.