# Mx - Drawing API

**URL:** <https://forum.kirupa.com/t/mx-drawing-api/27808>\
**Category:** flash\
**Created:** [August 6, 2003, 8:15pm UTC](https://forum.kirupa.com/t/mx-drawing-api/27808 "2003-08-06T20:15:19Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![grandsp5](https://avatars.discourse-cdn.com/v4/letter/g/6bbea6/32.png) [@grandsp5](https://forum.kirupa.com/u/grandsp5)\
**Post date:** [August 6, 2003, 8:15pm UTC](https://forum.kirupa.com/t/mx-drawing-api/27808/1 "2003-08-06T20:15:19Z")

</div>

I got this code for drawing polyhedrons with the drawing API from a tutorial but I don’t understand what everthing does. I get the first 5 lines but then it loses me. Can someone break it down line by line? The biggest thing I dont get is how it acceses the position in the array.

[AS]  
\_root.createEmptyMovieClip(“holder”,1); //creates clip  
holder.lineStyle(1,0,100);//defines line style  
width=30;//sets half the width of the square

myPoints=[[50-width,50-width],[50+width,50-width],[50+width,50+width],[50-width,50+width],[50-width,50-width]];  
//array with the 5 points needed to define the square

holder.moveTo(this.myPoints[0][0],this.myPoints[0][1]);  
//moves it to the starting point  
for (var j=1;j \< myPoints.length;j++)  
holder.lineTo(this.myPoints[j][0],this.myPoints[j][1]);  
//here i am lost  
[/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:** [August 6, 2003, 8:27pm UTC](https://forum.kirupa.com/t/mx-drawing-api/27808/2 "2003-08-06T20:27:06Z")

</div>

Which part exactly don’t you understand? The for loop or the multidimensional arrays (this.myPoints[j][0]), or both?

---

<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 6, 2003, 8:33pm UTC](https://forum.kirupa.com/t/mx-drawing-api/27808/3 "2003-08-06T20:33:08Z")

</div>

array. I understand exactly what the for loop does.

---

<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 6, 2003, 8:44pm UTC](https://forum.kirupa.com/t/mx-drawing-api/27808/4 "2003-08-06T20:44:49Z")

</div>

Ok, the myPoints array contains 5 items. But if you look carefully, those 5 items are actually arrays that contain 2 items ([] signifies an array).

So each item in the myPoints array is actually another array.

Arrays start counting from 0, so those sub arrays are basically like…  
[position0, position1]

So now for the script…  
[As]this.myPoints[j][0][/AS]

You know this.myPoints is the main array the contains the points so this.myPoints[j] gets the position of the item in the main array, and the [0] gets the position of the item at position0 in the subArray (array within the myPoints item array). Naturally to get the 2nd position you would change [0] to [1] (which is in the script as well).

So basically [AS]holder.lineTo(this.myPoints[j][0],this.myPoints[j][1]);[/AS]

lineTo works like this… lineTo(x,y), so basically the script gets the position in the this.myPoints[j][0] array for the x position and the position in the this.myPoints[j][1]) array for the y position and then it draws a line there.

Does that help any?

---

<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 6, 2003, 9:39pm UTC](https://forum.kirupa.com/t/mx-drawing-api/27808/5 "2003-08-06T21:39:07Z")

</div>

Oh yeah. See I am used to c++ where [] accesses a position in an array, not creates a new one. I thought it was trying to call 2 positions out of a 1 demensional array. I get it now. Thanks

---

<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 6, 2003, 9:41pm UTC](https://forum.kirupa.com/t/mx-drawing-api/27808/6 "2003-08-06T21:41:30Z")

</div>

Yeah, in Flash [] creates an array and arrayName[] accesses a position in an array. And in the case of multidimensional arrayes it would be arrayName[][] or even arrayName[][][] so on and so forth 🙂

Glad to help clear things 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:** [August 6, 2003, 9:43pm UTC](https://forum.kirupa.com/t/mx-drawing-api/27808/7 "2003-08-06T21:43:53Z")

</div>

Yup. Thanks a bunch. On a totally unrelated note, does recursion work in Flash?

---

<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 6, 2003, 9:46pm UTC](https://forum.kirupa.com/t/mx-drawing-api/27808/8 "2003-08-06T21:46:32Z")

</div>

Yes, I believe so. I don’t really work with recursive math in Flash though so i’m not entirely sure if/how it works.

---

<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 6, 2003, 9:52pm UTC](https://forum.kirupa.com/t/mx-drawing-api/27808/9 "2003-08-06T21:52:49Z")

</div>

ok. 🙂 thanks
