# Bantumi coders!

**URL:** <https://forum.kirupa.com/t/bantumi-coders/34331>\
**Category:** Uncategorized\
**Created:** [October 31, 2003, 3:41pm UTC](https://forum.kirupa.com/t/bantumi-coders/34331 "2003-10-31T15:41:15Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![pom](https://avatars.discourse-cdn.com/v4/letter/p/f07891/32.png) [@pom](https://forum.kirupa.com/u/pom)\
**Post date:** [October 31, 2003, 3:41pm UTC](https://forum.kirupa.com/t/bantumi-coders/34331/1 "2003-10-31T15:41:15Z")

</div>

> _Started by Iam Montoya_  
> Code Breakdown: Part I

1. establish four or five colors for the stones.  
Suggestion: We could also use four or five nice graphics, instead of just changing RGB for a circle. How would we use the graphics instead of just vector circles? How would the code change? (Meaning, we wont be able to just attachMovie at that point, or we would have to attach it four or five times.)

2. Once all 48 seeds are loaded and on screen, they need to be distributed to the 12 wells. How should we do that? Should we just put them there automatically? Should we show animation of stones going over there one by one?

3. Every well needs to show a number that displays how many stones are in each well.  
1-2, Ok, but I think that the real problem is not distributing the stones, but it’s placing them aroung the board when the user has decided to play.

3 is easy.

1. AI :trout:

---

<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:** [October 31, 2003, 3:50pm UTC](https://forum.kirupa.com/t/bantumi-coders/34331/2 "2003-10-31T15:50:30Z")

</div>

I started with step 1 of phase I.

[AS]

//establish colors to be used and put then in the array "colors"  
colors=[“FF0000”,“00CCFF”,“0000FF”,“FF9900”];  
//bring the seeds into the movie and assign the seeds a random color  
for(i=0;i\<48;i++){ //we’re gonna do this 48 times, starting at 0 through 48.  
randomcolor=Math.floor(math.Random()\*4); //choose a random number each time  
this.attachMovie(“seed”,“seed”+i,i); //attach a new instance and give it a new name  
colorassigned=(colors[randomcolor]); //use random number from “randomcolor” to pick value from the “colors” array.  
colorassigned=“0x”+colorassigned; //add “0x” in front of it, so we can use the string as a full hex number in setRGB() below;   
mycolor=new Color(“seed”+i); //create a new color object for each seed created in the loop  
mycolor.setRGB(colorassigned); //set the color of each object

}

[/AS]

btw, I know you guys know how to do this. Im commenting the code, because I figure we will use this later to demonstrate to the rest of the users how we completed the project. Heck, we should probably submit it to a magazine when we’re done. (Computer Arts is my choice, or Kirupa…the Magazine).

Change the code at will, but please post any new changes.

---

<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:** [October 31, 2003, 3:52pm UTC](https://forum.kirupa.com/t/bantumi-coders/34331/3 "2003-10-31T15:52:06Z")

</div>

That covers step1. Change it at will.

Pom, you got step 2?

Should we attach an updated FLA every time?

---

<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:** [October 31, 2003, 4:20pm UTC](https://forum.kirupa.com/t/bantumi-coders/34331/4 "2003-10-31T16:20:25Z")

</div>

I don’t have Flash at the moment, but we could discuss HOW we’re going to do step 2 and 2bis 🙂

---

<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:** [October 31, 2003, 4:37pm UTC](https://forum.kirupa.com/t/bantumi-coders/34331/5 "2003-10-31T16:37:12Z")

</div>

> \*Originally posted by Iammontoya \*  
> \*\*I started with step 1 of phase I.

[AS]

//establish colors to be used and put then in the array “colors”  
colors=[“FF0000”,“00CCFF”,“0000FF”,“FF9900”];  
//bring the seeds into the movie and assign the seeds a random color  
for(i=0;i\<48;i++){ //we’re gonna do this 48 times, starting at 0 through 48.  
randomcolor=Math.floor(math.Random()\*4); //choose a random number each time  
this.attachMovie(“seed”,“seed”+i,i); //attach a new instance and give it a new name  
colorassigned=(colors[randomcolor]); //use random number from “randomcolor” to pick value from the “colors” array.  
colorassigned=“0x”+colorassigned; //add “0x” in front of it, so we can use the string as a full hex number in setRGB() below;   
mycolor=new Color(“seed”+i); //create a new color object for each seed created in the loop  
mycolor.setRGB(colorassigned); //set the color of each object

}

[/AS]

btw, I know you guys know how to do this. Im commenting the code, because I figure we will use this later to demonstrate to the rest of the users how we completed the project. Heck, we should probably submit it to a magazine when we’re done. (Computer Arts is my choice, or Kirupa…the Magazine).

Change the code at will, but please post any new changes. \*\*  
Monty, if you want the loop to run 48 times, you either have to change the condition to \<= 47 or \< 48. \< 47 will run the loop 47 times if you’re starting from 0.

Also for the stones, I was thinking we could use a single graphic for all the stones and just change its tint. Maybe we could have EG come up with something.

---

<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:** [October 31, 2003, 4:52pm UTC](https://forum.kirupa.com/t/bantumi-coders/34331/6 "2003-10-31T16:52:32Z")

</div>

What do you mean? It says \<48. 🙂 j/k It said 47 before because in the original code I was duplicating the movie clip and not attaching it. Forgot to change it back…hhehee…thanks for the update.

Hmm… if you call me Monty Im gonna change my name… yeah… that’s what Im gonna do! 🙂

---

<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:** [October 31, 2003, 4:53pm UTC](https://forum.kirupa.com/t/bantumi-coders/34331/7 "2003-10-31T16:53:46Z")

</div>

The code above is using a single graphic, just changing the RGB value. I thought, however, that more colorful stones in PS or something would look nice. I’ll post an amateurish example later.

---

<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:** [October 31, 2003, 4:58pm UTC](https://forum.kirupa.com/t/bantumi-coders/34331/8 "2003-10-31T16:58:32Z")

</div>

Guys, why aren’t we doing this in AS2? :sure:

😛

---

<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:** [October 31, 2003, 4:59pm UTC](https://forum.kirupa.com/t/bantumi-coders/34331/9 "2003-10-31T16:59:17Z")

</div>

lol i would love to, but i dont know how many of us own mx2004

---

<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:** [October 31, 2003, 5:06pm UTC](https://forum.kirupa.com/t/bantumi-coders/34331/10 "2003-10-31T17:06:14Z")

</div>

how about we create a class and expand on it with prototypes?

```auto

BantumiClass = function () // constructor
{ 
	this.timeline = _root.createEmptyMovieClip("seeds", 0);
	this.colors = ["FF0000","00CCFF","0000FF","FF9900"];
} 

bcp = BantumiClass.prototype; // lazy shortcut

bcp.attachPiece = function (timeline, i)
{
	return timeline.attachMovie("seed", "seed"+i, i); // attaches a seed onto the stage
}

bcp.setColor = function( mc )
{
var colorObj = new Color( mc ),
randColor = Math.floor(math.Random()*4);
colorObj.setRGB(randColor);
}

/*
bcp.setXY = function (mc,x,y)
*/

bcp.addPiece = function (well, i)
{
var clip = well.attachPiece(i);
this.setColor(clip);
//setXY(clip,x,y)
}

bcp.createWell = function (wellNumber)
{
var well = this.timeline.createEmptyMovieClip("well"+wellNumber, wellNumber)
for ( var i=0 ; i<4 ; i++ ) this.addPiece(well, i);
}

bcp.init = function ()
{
for ( var n=0 ; n<8 ; n++ ) this.createWell(n);
}

delete bcp;

```

Im sure a lot of this can be optimized or cleaned, i’ll probably post a modified version once i get home from school 🙂

---

<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:** [October 31, 2003, 5:08pm UTC](https://forum.kirupa.com/t/bantumi-coders/34331/11 "2003-10-31T17:08:59Z")

</div>

Here’s an example.

---

<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:** [October 31, 2003, 5:09pm UTC](https://forum.kirupa.com/t/bantumi-coders/34331/12 "2003-10-31T17:09:42Z")

</div>

I don’t have MX 2004, but I will help whenever possible.

Ivan, I edited your code slightly… [AS]//establish colors to be used and put then in the array "colors"  
colors = [“FF0000”, “00CCFF”, “0000FF”, “FF9900”];  
for (var i = 1; i\<=48; i++) {  
//get a random color chosen from the colors array  
var randomColor = “0x”+colors[random(colors.length)];  
//attach clip using newSeed as an ID for later reference  
var newSeed = this.attachMovie(“seed”, “seed”+i, i);  
//create color object assigned to newSeed clip and set the color to the random color chosen  
var myColor = new Color(newSeed).setRGB(randomColor);  
}[/AS]

---

<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:** [October 31, 2003, 5:10pm UTC](https://forum.kirupa.com/t/bantumi-coders/34331/13 "2003-10-31T17:10:13Z")

</div>

I own MX2004, but I hate it. Until I love it, Im not touching AS2 unless Im forced.

I hate FlashMX2004 professional, that is. The other products seem fine.

---

<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:** [October 31, 2003, 5:11pm UTC](https://forum.kirupa.com/t/bantumi-coders/34331/14 "2003-10-31T17:11:45Z")

</div>

I like the streamlined code, Lost.

---

<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:** [October 31, 2003, 5:14pm UTC](https://forum.kirupa.com/t/bantumi-coders/34331/15 "2003-10-31T17:14:13Z")

</div>

> \*Originally posted by lostinbeta \*  
> \*\*I don’t have MX 2004, but I will help whenever possible.

Ivan, I edited your code slightly… [AS]//establish colors to be used and put then in the array “colors”  
colors = [“FF0000”, “00CCFF”, “0000FF”, “FF9900”];  
for (var i = 1; i\<=48; i++) {  
//get a random color chosen from the colors array  
var randomColor = “0x”+colors[random(colors.length)];  
//attach clip using newSeed as an ID for later reference  
var newSeed = this.attachMovie(“seed”, “seed”+i, i);  
//create color object assigned to newSeed clip and set the color to the random color chosen  
var myColor = new Color(newSeed).setRGB(randomColor);  
}[/AS] \*\*  
There’s a problem with using setRGB, though. When you use it on a graphic, it will force a fill, so you’ll basically get circle’s of different colors.  
I was thinking of having a semi-transparent fill inside each symbol and we could just change that so it looks like it’s being tinted.  
Otherwise, we could always just use those four graphics above and randomly load them:

```auto
for (var i = 0; i < 48; ++i) {
this.attachMovie("seed"+random(4), "seed"+i, i); // assuming the four marbles are named "seed0", "seed1", etc...to "seed3"
}

```

---

<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:** [October 31, 2003, 5:15pm UTC](https://forum.kirupa.com/t/bantumi-coders/34331/16 "2003-10-31T17:15:51Z")

</div>

> \*Originally posted by Iammontoya \*  
> \*\*I like the streamlined code, Lost. \*\*

Thanks Ivan, if you want more streamlined you can go [AS]colors = [“FF0000”, “00CCFF”, “0000FF”, “FF9900”];  
for (var i = 1; i\<=48; i++) {  
new Color(this.attachMovie(“seed”, “seed”+i, i)).setRGB(“0x”+colors[random(colors.length)]);  
}[/AS] But frankly, that gets to the point where it’s just a pain to read and manage 😛

---

<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:** [October 31, 2003, 5:16pm UTC](https://forum.kirupa.com/t/bantumi-coders/34331/17 "2003-10-31T17:16:53Z")

</div>

gotta love those one-liners 😛

---

<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:** [October 31, 2003, 5:17pm UTC](https://forum.kirupa.com/t/bantumi-coders/34331/18 "2003-10-31T17:17:18Z")

</div>

true…Thor… I only used setRGB for our current example. What I would really like to do is use graphics like the attached (Im sure someone will do better). Im not sure how I would go about that, though, because at that point, tint and RGB are both out. We’ll just need to use the 4 separate graphics. Does that make sense?

---

<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:** [October 31, 2003, 5:17pm UTC](https://forum.kirupa.com/t/bantumi-coders/34331/19 "2003-10-31T17:17:52Z")

</div>

you’re scaring me, Lost.

---

<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:** [October 31, 2003, 5:18pm UTC](https://forum.kirupa.com/t/bantumi-coders/34331/20 "2003-10-31T17:18:11Z")

</div>

That should be easy Ivan.

Store the linkageIDs of the clips in an array and choose from that during the attachMovie().

[edit]it’s halloween, i’m allowed to be scary :thumb:[/edit]

[Next page](https://forum.kirupa.com/t/bantumi-coders/34331.md?page=2)
