# beginFill method using specified colors!

**URL:** <https://forum.kirupa.com/t/beginfill-method-using-specified-colors/267016>\
**Category:** flash\
**Created:** [July 27, 2008, 2:58pm UTC](https://forum.kirupa.com/t/beginfill-method-using-specified-colors/267016 "2008-07-27T14:58:10Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Mesilane](https://avatars.discourse-cdn.com/v4/letter/m/dec6dc/32.png) [@Mesilane](https://forum.kirupa.com/u/Mesilane)\
**Post date:** [July 27, 2008, 2:58pm UTC](https://forum.kirupa.com/t/beginfill-method-using-specified-colors/267016/1 "2008-07-27T14:58:10Z")

</div>

Hei!

When i use:

```auto

beginFill(Math.random()*0xffffff, 100)

```

i get color picked randomly. But mostly they appear to be quite… ugly, if to be straighforward. How can i use random specified colors? Let’s say I set the calues like example below:

```auto

col1 = 0x99cc00
col2 = 0xff6600

```

And it randomly picks one color of specified ones…

---

<div class="post-metadata">

**Author:** ![krilnon](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/krilnon/32/34_2.png) [@krilnon](https://forum.kirupa.com/u/krilnon)\
**Post date:** [July 27, 2008, 3:14pm UTC](https://forum.kirupa.com/t/beginfill-method-using-specified-colors/267016/2 "2008-07-27T15:14:50Z")

</div>

```auto
var colors:Array = [0xffffff, 0x000000, 0xf0f0f0, 0x0f0f0f];
beginFill(int(Math.random() * a.length), 100);

```

You can use more complicated AS if you don’t want to colors to repeat immediately.

---

<div class="post-metadata">

**Author:** ![Mesilane](https://avatars.discourse-cdn.com/v4/letter/m/dec6dc/32.png) [@Mesilane](https://forum.kirupa.com/u/Mesilane)\
**Post date:** [July 27, 2008, 4:35pm UTC](https://forum.kirupa.com/t/beginfill-method-using-specified-colors/267016/3 "2008-07-27T16:35:54Z")

</div>

where the “a.length” comes from?

---

<div class="post-metadata">

**Author:** ![senocular](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/senocular/32/7217_2.png) [@senocular](https://forum.kirupa.com/u/senocular)\
**Post date:** [July 27, 2008, 4:39pm UTC](https://forum.kirupa.com/t/beginfill-method-using-specified-colors/267016/4 "2008-07-27T16:39:30Z")

</div>

[QUOTE=Mesilane;2365329]where the “a.length” comes from?[/QUOTE]

That code sample looks a little incomplete. Here is a completed example:

```auto
var colors:Array = [0xffffff, 0x000000, 0xf0f0f0, 0x0f0f0f];
var randomColorIndex:Number = Math.floor(Math.random() * colors.length);
var randomColor:Number = colors[randomColorIndex];
beginFill(randomColor, 100);

```

---

<div class="post-metadata">

**Author:** ![krilnon](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/krilnon/32/34_2.png) [@krilnon](https://forum.kirupa.com/u/krilnon)\
**Post date:** [July 27, 2008, 5:13pm UTC](https://forum.kirupa.com/t/beginfill-method-using-specified-colors/267016/5 "2008-07-27T17:13:19Z")

</div>

Oops, sorry about the incomplete code. I originally had named ‘colors’ ‘a’, and I guess I just forgot about the array access or something. :trout:

---

<div class="post-metadata">

**Author:** ![Mesilane](https://avatars.discourse-cdn.com/v4/letter/m/dec6dc/32.png) [@Mesilane](https://forum.kirupa.com/u/Mesilane)\
**Post date:** [July 27, 2008, 6:45pm UTC](https://forum.kirupa.com/t/beginfill-method-using-specified-colors/267016/6 "2008-07-27T18:45:08Z")

</div>

Thank You! I got it now (:
