How to target this?

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??

Thanks!

did you try this[“copy”+i] ??

yes, I tried that as well. It doesn’t work unfortunately :frowning:

Any other ideas?

Cheers.

Anyone??

I just can’t believe there’s no flashguru that doesn’t know this so… * bump *

ok… well this is not very dynamic, but if you knew exactly where these mc’s were going to reside, then you could call out to it.

so if you used loadMovie to load this swf into a movie clip called. “holder” Then the prototype script might be something 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.holder["copy"+i]._x += 50*x;
                _root.holder["copy"+i]._y += 50*y;
                x++;
        }
}
this.onLoad = function(){
        _root.holder.original.duplicateMC();
}

maybe…

just wondering… why not use attachMovie instead? I find it more convienient.

Thanks David.

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?

Thanks.

This actually means no one knows?? * gets QotSA music inside head * :slight_smile:

where are all you ASgurus: LiB, Ilyas, Kax or others??

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 :wink:

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 += 50
y;
x++;
}
};
original.duplicateMC();[/AS]

And because I am SUPER BORED I decided to obfuscate this a bit…

[AS]MovieClip.prototype.duplicateMC = function() {
this._visible=false, amount=16, x=1, y=0;
for(i=0; i<amount; i++){mc=this.duplicateMovieClip(“copy”+i, i), i%4==0 ? (x=0, y++) : null, mc._x=50x, mc._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 :wink:

After viewing my obfuscated code, I just realized I did something there that I forgot to post 2 posts ago :hangover:

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”

And y+=1 can be said as y++ as well…

[AS]MovieClip.prototype.duplicateMC = function() {
amount = 16;
x = 1;
y = 0;
for (i=1; i<amount; i++) {
//trace(“x:” + x + " y: " + y);
mc = this.duplicateMovieClip(“copy”+i, i);
if (i%4 == 0) {
x = 0;
y++;
}
mc._x += 50x;
mc._y += 50
y;
x++;
}
};
original.duplicateMC();[/AS]

Wow, thanks a lot man!

I wish I could come up with stuff like that when I’m superbored :stuck_out_tongue:

I think I have to study on your obfuscated script: I think I’ll have to study on that a bit before I’ll get it

And the y++ part: :bounce: stupid me!! I should have seen that myself.

Anyway, thanks a lot, I’m happy!

Glad it helped :slight_smile:

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 :stuck_out_tongue:

I posted that method here because I did get bored and I wanted to see how many lines I could get it down to :stuck_out_tongue:

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?

When using duplicateMovieClip or attachMovie you do it the way I did above…

[AS]mc = this.duplicateMovieClip(“copy”+i, i);[/AS]

But any other way you just do…

variableName = clipInstanceName

(and don’t forget about _root, _parent, this, etc if you need them)

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.

the outdated menu I have been trying to work with has been confusing me to death… if you cannot recall the menu please visit
http://www.kirupaforum.com/forums/showthread.php?s=&threadid=20204

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.

Sure, I will help.

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.

Im already almost done coding it. I will explain in step by step detail in your other thread.