# \[MX\] need help adding array to AS

**URL:** <https://forum.kirupa.com/t/mx-need-help-adding-array-to-as/29334>\
**Category:** flash\
**Created:** [August 25, 2003, 8:47pm UTC](https://forum.kirupa.com/t/mx-need-help-adding-array-to-as/29334 "2003-08-25T20:47:18Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![jcs](https://avatars.discourse-cdn.com/v4/letter/j/439d5e/32.png) [@jcs](https://forum.kirupa.com/u/jcs)\
**Post date:** [August 25, 2003, 8:47pm UTC](https://forum.kirupa.com/t/mx-need-help-adding-array-to-as/29334/1 "2003-08-25T20:47:18Z")

</div>

I’ve been playing with a great code Ilyas developed that waves an image. I’m making an underwater scene and removed the controllers so the image waves all the time.

Trouble is, I have three clips I want to wave at the same time and I could use some explanation about how I could use an array to do this and still position each clip independently.

Any help (Ilyas?) would be appreciated.

Thanks,  
JC

[http://www.juniorastronauts.com/mermaid3.html](http://www.juniorastronauts.com/mermaid3.html)

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [August 25, 2003, 8:58pm UTC](https://forum.kirupa.com/t/mx-need-help-adding-array-to-as/29334/2 "2003-08-25T20:58:37Z")

</div>

Hey jcs 🙂

What do you want to use an array for exactly?

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [August 26, 2003, 2:10pm UTC](https://forum.kirupa.com/t/mx-need-help-adding-array-to-as/29334/3 "2003-08-26T14:10:51Z")

</div>

Hey Ilyas :thumb:

Well, I was thinking that you have  
[AS]clip = “vache”[/AS]  
in your AS (which I changed to “fig1” in mine) and that if I could make an array that contained “fig1”, “fig2”, and “fig3” and had [AS]clip = thatArray[/AS] that I could apply the rest of the code to all 3 clips.

sounds like I’m off track … ?

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [August 26, 2003, 2:15pm UTC](https://forum.kirupa.com/t/mx-need-help-adding-array-to-as/29334/4 "2003-08-26T14:15:57Z")

</div>

Can you post the code you’re refering to? All I could find was this one: [http://www.kirupaforum.com/forums/showthread.php?s=&threadid=13149&highlight=lifaros](http://www.kirupaforum.com/forums/showthread.php?s=&threadid=13149&highlight=lifaros) and there’s no vache around 😛

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [August 26, 2003, 2:27pm UTC](https://forum.kirupa.com/t/mx-need-help-adding-array-to-as/29334/5 "2003-08-26T14:27:05Z")

</div>

here 'tis:

[AS]  
/\*\*\* Nom de linkage du clip \*\*\*/  
clip=“vache”;

/\*\*\* Constantes \*\*\*/  
startX=65; // position du coin gauche de l’image  
startY=60; // position du coin gauche de l’image  
amplitude=2; // amplitude des oscillations - géré par les scrollers  
angleIncrement=3; // vitesse des oscillations - géré par les scrollers  
periode=9; // période des oscillations  
clips=[]; // array qui contiendra tous les clips dupliqués

/\*\*\* Fonctions  
- init: initialise les variables width et height  
- drawMask: dessine un masque de longueur et largeur spécifiée  
- oscillate: donne le mouvement oscillatoire à une petite tranche d’image  
- splitImage: découpe le clip en un nombre spécifié de petites tranches  
_/  
function init(){  
this.createEmptyMovieClip(“container”,0);  
container.attachMovie(clip,clip,0);  
container.\_x=startX;  
container.\_y=startY;  
width=container.\_width;  
height=container.\_height;  
container.removeMovieClip();  
}  
function drawMask(targ,width,height){  
var mask=targ.createEmptyMovieClip(“mask”,1);  
mask.beginFill(0,100);  
mask.lineTo(width,0);  
mask.lineTo(width,height);  
mask.lineTo(0,height);  
mask.endFill();  
return mask;  
}  
function oscillate(targ){  
targ.\_y=startY+amplitudeMath.sin(targ.angle/periode);  
targ.angle+=angleIncrement;  
}  
function splitImage(slices){  
var j=1;  
for (var i=0;i \< slices;i++){  
clips.push(createEmptyMovieClip(“container”+j,j++));  
clips.attachMovie(clip,clip,0);  
clips_.\_x=startX;  
clips\*.\_y=startY;  
clips\*.angle=i;  
var index=width/slices;  
var mask=drawMask(clips\*,index,height);  
mask.\_x=i_index;  
mask.\_y=0;  
clips_.setMask(mask);  
clips\*.onEnterFrame=function(){  
oscillate(this);  
}  
}  
}

/\*\*\* Exécute les fonctions \*\*\*/  
init();  
splitImage(30);  
[/AS]

I replaced vache with fig1 and changed the linkage ID in the movieclip. --that-- works fine, but I want to extend the code to two other clips so 3 are waving onsreen at the same time.

You know I always ask you the craziest things, Ilyas. :azn:

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [August 26, 2003, 2:45pm UTC](https://forum.kirupa.com/t/mx-need-help-adding-array-to-as/29334/6 "2003-08-26T14:45:18Z")

</div>

All right, I don’t have Flash here, so it’s kind of hard to modifiy, but basically, you’ll just have to make a big function that will trigger the init() and the split() functions. The only problem you’ll have is that you’ll have to attach all the clips within the container, and keep track of those containers.

If you don’t manage to make it, I’ll try to make an example for you when I get home 🙂

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [August 26, 2003, 2:59pm UTC](https://forum.kirupa.com/t/mx-need-help-adding-array-to-as/29334/7 "2003-08-26T14:59:25Z")

</div>

deal. 😉

I’ll keep hacking away on it.

Here’s my larger issue: I’m at the point where I can understand AS, take examples apart and piece them back together for my purposes, but it’s not my _lingua franca_ - I can’t just start writing it. Anyone know of a good, solid book or Web resource that can help me over that hump?

Ilyas, look forward to your help!

JCS

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [August 26, 2003, 10:01pm UTC](https://forum.kirupa.com/t/mx-need-help-adding-array-to-as/29334/8 "2003-08-26T22:01:50Z")

</div>

i was at the same point a little while ago. What i did is after I did all the tutorials, I did them again without ever looking at the steps. It helps you get a feel for how to create code rather than just understand it. Also try making some basic stuff, sliders, music players, a picture or 2 with the drawing api, and some duplicateMovie animations. It will help.

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [August 26, 2003, 10:13pm UTC](https://forum.kirupa.com/t/mx-need-help-adding-array-to-as/29334/9 "2003-08-26T22:13:00Z")

</div>

that’s a good tip. I like it. Thanks grandsp5(-:

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [August 26, 2003, 10:13pm UTC](https://forum.kirupa.com/t/mx-need-help-adding-array-to-as/29334/10 "2003-08-26T22:13:42Z")

</div>

anytime

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [August 27, 2003, 3:37pm UTC](https://forum.kirupa.com/t/mx-need-help-adding-array-to-as/29334/11 "2003-08-27T15:37:46Z")

</div>

I noticed the movie in the link you posted made my processor usage jump to 68% (AMD 2600). That’s just with one pic.

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [August 27, 2003, 4:17pm UTC](https://forum.kirupa.com/t/mx-need-help-adding-array-to-as/29334/12 "2003-08-27T16:17:08Z")

</div>

Nocturn,  
thanks for the tip. Maybe I should find a less cumbersome approach …

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [August 27, 2003, 7:14pm UTC](https://forum.kirupa.com/t/mx-need-help-adding-array-to-as/29334/13 "2003-08-27T19:14:34Z")

</div>

All right, here you go:

```auto
function makeWave (_mc, slices) {
	i++ ;
	var container = init (_mc, i) ;
	trace (container.width);
	splitImage(container, _mc, slices);
}
function init(cl, dep) {
	var container = this.createEmptyMovieClip("container"+dep, dep);
	container.startX = 65;
	container.startY = 60;
	container.amplitude = 10;		
	container.angleIncrement = 3;	
	container.periode = 9;		
	container.clips = [];
	var clip = container.attachMovie(cl, cl, 0);
	container._x = container.startX;
	container._y = container.startY;
	container.width = container._width;
	container.height = container._height;
	clip.removeMovieClip();
	return container ;
}
function drawMask(targ, width, height){
        var mask = targ.createEmptyMovieClip("mask", 1);
        mask.beginFill(0,100);
        mask.lineTo(width,0);
        mask.lineTo(width,height);
        mask.lineTo(0,height);
        mask.endFill();
        return mask;
}
function oscillate(){
	var t = this._parent ;
	this._y = t.startY + t.amplitude * Math.sin(this.angle / t.periode);
	this.angle += t.angleIncrement;
}
function splitImage(cont, targ, slices){
	var j=1;
	for (var i=0;i < slices;i++){
		cont.clips.push(cont.createEmptyMovieClip("container"+j,j++));
		trace (cont.clips*)
		cont.clips*.attachMovie(targ, targ, 0);
		cont.clips*._x = cont.startX;
		cont.clips*._y = cont.startY;
		cont.clips*.angle = i;
		var index = cont.width/slices;
		var mask = drawMask(cont.clips*,index,cont.height);
		mask._x = i * index;
		mask._y = 0;
		cont.clips*.setMask(mask);
		cont.clips*.onEnterFrame = oscillate ;
	}
}
makeWave("vache", 20) ;
makeWave("lait", 20) ;
//... And whatever clip you like...

```

pom 🙂

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [August 27, 2003, 7:20pm UTC](https://forum.kirupa.com/t/mx-need-help-adding-array-to-as/29334/14 "2003-08-27T19:20:49Z")

</div>

Ilyas, you are an animal!

So I was mistaken - I really wanted a function I could apply to several clips instead of an array of clips I dumped into one fcn.

Thanks - I’m going to be able to play with this later today. If it doesn’t toast my processor like Nocturn mentioned, I’ll pass around the link when it’s up.

JCS

=)

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [August 27, 2003, 9:00pm UTC](https://forum.kirupa.com/t/mx-need-help-adding-array-to-as/29334/15 "2003-08-27T21:00:13Z")

</div>

I’d love to see the outcome of your work :beam:

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [August 27, 2003, 9:08pm UTC](https://forum.kirupa.com/t/mx-need-help-adding-array-to-as/29334/16 "2003-08-27T21:08:54Z")

</div>

it should be pretty funny. gimmie a day or so - work’s jamming me up … 😉

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [September 3, 2003, 9:10pm UTC](https://forum.kirupa.com/t/mx-need-help-adding-array-to-as/29334/17 "2003-09-03T21:10:52Z")

</div>

one more question :}

Ilyas, used your AS and it worked, but all three clips appeared in the same location. I am trying to add to the code so I can control the \_x and \_y of each clip.

I _think_ I need to control it by adding properties to the imageWave fcn. but I can’t square it quite right. Here’s what I’m thinking:

[AS]  
function makeWave (\_mc, slices, controlX, controlY) {  
i++ ;  
var container = init (\_mc, i) ;  
trace (container.width);  
splitImage(container, \_mc, slices);  
}  
function init(cl, dep) {  
var container = this.createEmptyMovieClip(“container”+dep, dep);  
container.startX = controlX;  
container.startY = controlY;  
container.amplitude = 5;  
container.angleIncrement = 3;  
container.periode = 9;  
container.clips = [];  
var clip = container.attachMovie(cl, cl, 0);  
container.\_x = container.startX;  
container.\_y = container.startY;  
container.width = container.\_width;  
container.height = container.\_height;  
clip.removeMovieClip();  
return container ;  
}  
function drawMask(targ, width, height){  
var mask = targ.createEmptyMovieClip(“mask”, 1);  
mask.beginFill(0,100);  
mask.lineTo(width,0);  
mask.lineTo(width,height);  
mask.lineTo(0,height);  
mask.endFill();  
return mask;  
}  
function oscillate(){  
var t = this.\_parent ;  
this.\_y = t.startY + t.amplitude \* Math.sin(this.angle / t.periode);  
this.angle += t.angleIncrement;  
}  
function splitImage(cont, targ, slices){  
var j=1;  
for (var i=0;i \< slices;i++){  
cont.clips.push(cont.createEmptyMovieClip(“container”+j,j++));  
trace (cont.clips\*)  
cont.clips\*.attachMovie(targ, targ, 0);  
cont.clips\*.\_x = cont.startX;  
cont.clips\*.\_y = cont.startY;  
cont.clips\*.angle = i;  
var index = cont.width/slices;  
var mask = drawMask(cont.clips\*,index,cont.height);  
mask.\_x = i \* index;  
mask.\_y = 0;  
cont.clips\*.setMask(mask);  
cont.clips\*.onEnterFrame = oscillate ;  
}  
}  
makeWave(“fig1”, 20, 20, 60) ;  
makeWave(“fig2”, 20, 50, 50) ;  
makeWave(“fig3”, 20, 100, 60) ;  
//… And whatever clip you like…  
[/AS]

But that doesn’t work. What am i doing wrong?  
JCS

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [September 3, 2003, 9:35pm UTC](https://forum.kirupa.com/t/mx-need-help-adding-array-to-as/29334/18 "2003-09-03T21:35:44Z")

</div>

Hi,

I noticed that you pass the control values to the makeWave function but it doesn’t then pass them on to the init function.

Change your call to init to be

var container = init (\_mc, i, controlX, controlY) ;

and change init to accept 4 parameters.

function init(cl, dep, ctrlX, ctrlY) {  
.  
.

```
    container.startX = ctrlX;
    container.startY = ctrlY;
  .
  .
  .

```

}

Hope this helps,

Liz

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [September 3, 2003, 10:00pm UTC](https://forum.kirupa.com/t/mx-need-help-adding-array-to-as/29334/19 "2003-09-03T22:00:15Z")

</div>

🙂 🙂 🙂 :beam:

thanks liz. worked great. will post the final product tomorrow

I love this board …

JCS

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [September 3, 2003, 10:16pm UTC](https://forum.kirupa.com/t/mx-need-help-adding-array-to-as/29334/20 "2003-09-03T22:16:38Z")

</div>

No problem :nerd:

Liz
