# Code Help

**URL:** https://forum.kirupa.com/t/code-help/185946
**Category:** Uncategorized
**Created:** [April 17, 2006, 11:16pm UTC](https://forum.kirupa.com/t/code-help/185946 "2006-04-17T23:16:34Z")
**Posts on this page:** 10
**Page:** 1

<div class="post-metadata">

### Author: ![artistwantab](https://avatars.discourse-cdn.com/v4/letter/a/bbce88/32.png) [@artistwantab](https://forum.kirupa.com/u/artistwantab)
#### Post date: [April 17, 2006, 11:16pm UTC](https://forum.kirupa.com/t/code-help/185946/1 "2006-04-17T23:16:34Z")

</div>

Can someone help turn this into a simple function that I can call when attaching a movie?

Also can you explain

```auto

[LEFT]while (this.i < 25) { this.i++;[/LEFT]

```

and  
what exactly is if and else doing.

I understand that If (ball == ball) then the ball is made invisible but that is always true because that is the only MC on the stage and called…right? So what does the else do? I understand whats its doing but If “If” is always true then it doesn’t use else right. I know I am missing something…

```auto
 [LEFT]MovieClip.prototype.particle = function () {
if (this._name == "ball") {
this._visible = false;
this.onMouseDown = function () {
this.i = 0;
};
while (this.i < 25) {
this.i++;
var rn = Math.floor (Math.random () * (300 - 25)) + 25;
this._xscale = rn;
this._yscale = rn;
this.duplicateMovieClip ("ball" + this.i, this.i);
removeMovieClip ("ball" + (this.i - 20));
updateAfterEvent ();
}
}
else {
this.x_speed *= .98;
this._alpha -= 0;
this._x += this.x_speed;
this._y += this.y_speed;
if (this._y > 450 || this._y < 0 || this._x > 750 || this._x < 0 || this._alpha <= 0) {
this.removeMovieClip ();
updateAfterEvent ();
}
}
};
 

[/LEFT]

 
 
 

```

The below .swf show how the movie is supposed to play. The only way I can get it to play that way is by placing a “for” statement within the MC. That is not the correct way to do it. So I would like someone help.

---

<div class="post-metadata">

### Author: ![joran420](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/joran420/32/2329_2.png) [@joran420](https://forum.kirupa.com/u/joran420)
#### Post date: [April 18, 2006, 1:18am UTC](https://forum.kirupa.com/t/code-help/185946/2 "2006-04-18T01:18:35Z")

</div>

while (this.i \< 25) {  
this.i++;

I think should be

do{  
this.i++  
}while(this.i \< 25)

is basically the same as

for( i = this.i ; i \< 25 ; i++){}  
or you could just do

for (;this.i \< 25 ; i++) {}

all 3 of those for this case would be evaluated the same way i believe

what specific parts dont you understand and maybe i can help explain them…(that effect is pretty dmn cool btw)

---

<div class="post-metadata">

### Author: ![matthewjumps](https://avatars.discourse-cdn.com/v4/letter/m/49beb7/32.png) [@matthewjumps](https://forum.kirupa.com/u/matthewjumps)
#### Post date: [April 18, 2006, 1:23am UTC](https://forum.kirupa.com/t/code-help/185946/3 "2006-04-18T01:23:20Z")

</div>

did you write that nice explosion code by yourself? and yet you dont know what if/else does and what while is all about?

the while is basically saying 'do whatever actions are in my brackets until the variable i equals 24 (ie less than 25)'  
on that i would probably put the “this.i++;” at the end of the actions inside the while brackets

edit: yea a for is better

```auto

for(i=0; i<25; i++) {
            var rn = Math.floor(Math.random()*(300-25))+25;
            this._xscale = rn;
            this._yscale = rn;
            this.duplicateMovieClip("ball"+this.i, this.i);
            removeMovieClip("ball"+(this.i-20));
            updateAfterEvent();
        }

```

---

<div class="post-metadata">

### Author: ![joran420](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/joran420/32/2329_2.png) [@joran420](https://forum.kirupa.com/u/joran420)
#### Post date: [April 18, 2006, 1:31am UTC](https://forum.kirupa.com/t/code-help/185946/4 "2006-04-18T01:31:44Z")

</div>

hehe yeh thats what i thought “■■■■ that effect is awesome for him not knowin wtf hes doin…” Im guessing its pilfered from somewhere…but thats a neat effect

---

<div class="post-metadata">

### Author: ![matthewjumps](https://avatars.discourse-cdn.com/v4/letter/m/49beb7/32.png) [@matthewjumps](https://forum.kirupa.com/u/matthewjumps)
#### Post date: [April 18, 2006, 1:34am UTC](https://forum.kirupa.com/t/code-help/185946/5 "2006-04-18T01:34:07Z")

</div>

yea my thoughts too - pilfered 😃

---

<div class="post-metadata">

### Author: ![artistwantab](https://avatars.discourse-cdn.com/v4/letter/a/bbce88/32.png) [@artistwantab](https://forum.kirupa.com/u/artistwantab)
#### Post date: [April 18, 2006, 1:34am UTC](https://forum.kirupa.com/t/code-help/185946/6 "2006-04-18T01:34:18Z")

</div>

> [@matthewjumps](#):
>
> did you write that nice explosion code by yourself?

Hello,

I took some explosion code and modified it. Unfortunatly when I tried to convert it from a prototype to a simple function I could not get it to work. I am very new to flash and I am not familiar with “while” so I thought maybe I am missing something.

If you notice the code works with an onRelease but when you play the swf No Release is needed.

I added a for statement to the MC to show an example of what I needed the above code converted to.

---

<div class="post-metadata">

### Author: ![artistwantab](https://avatars.discourse-cdn.com/v4/letter/a/bbce88/32.png) [@artistwantab](https://forum.kirupa.com/u/artistwantab)
#### Post date: [April 18, 2006, 1:52am UTC](https://forum.kirupa.com/t/code-help/185946/7 "2006-04-18T01:52:03Z")

</div>

> [@matthewjumps](#):
>
> yea my thoughts too - pilfered 😃

:hurt:  
I am guilty as charged. But I did change a few things.

Orginal code created by David Brushinski

Swf Below

```auto
movieclip.prototype.particle = function() {
 if (this._name == "mc") {
  this._visible = false;
  this.onMouseDown = function() {
   this.i = 0;
  };
  while (this.i<100) {
   this.i++;
   this.duplicateMovieClip("mc"+this.i, this.i);
  }
 } else {
  this.x_speed*=.98;
  this._alpha-=2;
  this._x += this.x_speed;
  this._y += this.y_speed;
  if (this._y>450 || this._y<0 || this._x>750 || this._x<0||this._alpha<=0) {
   this.removeMovieClip();
  }
 }
};

```

---

<div class="post-metadata">

### Author: ![artistwantab](https://avatars.discourse-cdn.com/v4/letter/a/bbce88/32.png) [@artistwantab](https://forum.kirupa.com/u/artistwantab)
#### Post date: [April 18, 2006, 2:06am UTC](https://forum.kirupa.com/t/code-help/185946/8 "2006-04-18T02:06:14Z")

</div>

Ok I tried your code and was similar to the results I was getting.

Refer to swf below.

The movie is just looping. I am sure it has something the onMouseDown but I have tried everything to get the same swf as the one above and can never do it unless I ad a “for” statement to the MC.

Grrr.

```auto
MovieClip.prototype.particle = function () {
 if (this._name == "ball") {
  this._visible = false;
  this.onMouseDown = function () {
   this.i = 0;
  };
  for (i = 0; i < 25; i++) {
   var rn = Math.floor (Math.random () * (300 - 25)) + 25;
   this._xscale = rn;
   this._yscale = rn;
   this.duplicateMovieClip ("ball" + this.i, this.i);
   removeMovieClip ("ball" + (this.i - 20));
   updateAfterEvent ();
  }
 }
 else {
  this.x_speed *= .98;
  this._alpha -= 0;
  this._x += this.x_speed;
  this._y += this.y_speed;
  if (this._y > 450 || this._y < 0 || this._x > 750 || this._x < 0 || this._alpha <= 0) {
   this.removeMovieClip ();
   updateAfterEvent ();
  }
 }
};

```

---

<div class="post-metadata">

### Author: ![joran420](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/joran420/32/2329_2.png) [@joran420](https://forum.kirupa.com/u/joran420)
#### Post date: [April 18, 2006, 3:01am UTC](https://forum.kirupa.com/t/code-help/185946/9 "2006-04-18T03:01:05Z")

</div>

and what are you trying to get it to do?

maybe your going about this wrong…why do you need to make it a function instead of a prototype?

then again im pretty new to AS too

---

<div class="post-metadata">

### Author: ![artistwantab](https://avatars.discourse-cdn.com/v4/letter/a/bbce88/32.png) [@artistwantab](https://forum.kirupa.com/u/artistwantab)
#### Post date: [April 18, 2006, 3:45am UTC](https://forum.kirupa.com/t/code-help/185946/10 "2006-04-18T03:45:35Z")

</div>

Mainly I want to understand the code. The way it is written I can’t understand all its features and can’t recreate it. I want the movie to work just like my first post but written without the “for statment” attached to MC and “onMouseDown”

Also having trouble finding someone to explain.

For instance.

```auto
this.onMouseDown = function() {

```

As you can see the movie still works with it?

```auto
if (this._name == "ball") {

```

Ball is the only MC so that is always true.

```auto
 else {
  this.x_speed *= .98;
  this._alpha -= 0;
  this._x += this.x_speed;
  this._y += this.y_speed;
  if (this._y > 450 || this._y < 0 || this._x > 750 || this._x < 0 || this._alpha <= 0) {
   this.removeMovieClip ();
   updateAfterEvent ();

```

If ball is always true then “else” is never used…right?

Just loops till ball is false.

The code is neccessary because if removed nothing happens.

Just a noob trying to understand.

Here is the Fla.
