title: AS3 Custom Cursor On Click
body: <p>I'm working on a painting game, that once you click on the brushes, the mouse switches to the graphical counterpart of said brushes and will let you paint on screen. If no brush has been selected, the mouse will remain the same.</p>
  <p>The Rectangle and the brushes are on a separate Movieclip, which allows me to layer png lines over it so you can fill in and draw.</p>
  <p>In the actions layer in the Scene 1, this is my code for changing the mouse:</p>
  <pre><code>var cursor_mc:MovieClip;
  
  if (CanvPark_mc.HugeSelected1 == true){
      cursor_mc = cursor1_mc;
  }else if(CanvPark_mc.MediumSelected1 == true) {
      cursor_mc = cursor2_mc;
  }else if(CanvPark_mc.SmallSelected1 == true) {
      cursor_mc = cursor3_mc;
  }
  
  
  stage.addEventListener(MouseEvent.MOUSE_MOVE,moveCursor);    
  function moveCursor(myEvent:MouseEvent) { 
      if(CanvPark_mc.SmallSelected1 == false, CanvPark_mc.MediumSelected1 == false, CanvPark_mc.HugeSelected1 == false)
      { Mouse.cursor=&quot;auto&quot;;
      }else{
      setChildIndex(cursor_mc, this.numChildren-1);
      cursor_mc.x = (mouseX); 
      cursor_mc.y = (mouseY); 
      Mouse.hide();  
      }
  }
  </code></pre>
  <p>Each brush has a boolean variable associated to it: Small, Medium and HugeSelected1, so that way, I can tell at all times in code which one is selected and which one isn't.</p>
  <p>Right now, running this code, in the start, nothing happens, but if I click any of the brushes, this pops up in the output.</p>
  <pre><code>TypeError: Error #2007: Parameter child must be non-null.
      at flash.display::DisplayObjectContainer/setChildIndex()
      at visibilityToggle/moveCursor()[visibilityToggle::frame1:42]
  </code></pre>
  <p>Seems to be pointing specifically at</p>
  <pre><code> setChildIndex(cursor_mc, this.numChildren-1);
  </code></pre>
  <p>I honestly don't know what's causing this error. I thought it would be this straight forward to change my mouse cursor.</p>
  <p>How can I fix this?</p>