4 Replies Latest reply on Nov 9, 2011 11:59 AM by Owen_Alextoys

    Change cursor color

    Owen_Alextoys Level 1

      Hello,

       

           I've got a simple coloring book that I'm developing. I've got most everything working but I'm having trouble getting the cursor to pick up the active color from a color array.

      The cursor is a movieclip called "mycursor_mc" There is a movie clip inside this called "CursorFill". I am trying to get the "CursorFill" movie clip to change to the currentColour value from the dynamic property array index.

       

      This is the section I was working on but it's not working:

       

      var mycursor_mc:cursor = new cursor();

      addChild(mycursor_mc);

      var m = new CursorFill();

           mycursor_mc.addChild(m);

       

       

       

       

      Here's the whole Action script:

       

      //Array to hold the colours

      var colorArray:Array=new Array(0xE97DB1,0xF58240,0xF9ED41,0x82C34D,0x00B0F0,0x935CA4,0xFFFFFF);

       

       

      //A new instance of the colour transform class.

      var colorTrans:ColorTransform=new ColorTransform;

       

       

      var currentColor:int=0;

       

       

      //This adds the ovals on the stage with the corresponding colour from the array

      //and with the mouse click event.

      for (var i:int = 0; i < colorArray.length; i++) {

           var marker:Sprite = new Sprite();

           marker.y=500+i*50;

       

           var c = new MarkerFill();

           c.buttonMode=true;

           marker.addChild(c);

       

       

       

       

       

           colorTrans.color=colorArray[i];

           c.transform.colorTransform=colorTrans;

           c.addEventListener(MouseEvent.CLICK, ovalsClick);

           c.arrayIndex=i;

       

           var o:Outline = new Outline();

           marker.addChild(o);

       

           addChild(marker);

      }

       

       

      //This creates a new instance of the cursor movie clip and adds it onto

      //the stage using the addChild method.

      var mycursor_mc:cursor = new cursor();

      addChild(mycursor_mc);

      var m = new CursorFill();

           mycursor_mc.addChild(m);

       

       

      //Hides the default cursor on the stage so it will not be shown.

      Mouse.hide();

       

       

      //Adds an event listener onto the stage with the enter frame event which

      //repeatedly executes the moveCursor function.

      stage.addEventListener(Event.ENTER_FRAME, moveCursor);

       

       

      //This function set the x & y positions of the custom cursor to the x & y positions

      //of the default cursor.

      function moveCursor(event:Event) {

        mycursor_mc.x=mouseX;

        mycursor_mc.y=mouseY;

      }

                

      //This sets the currentColour value from the dynamic property array index.

      function ovalsClick(e:MouseEvent):void {

           currentColor=e.currentTarget.arrayIndex;

      }

       

       

      //Adds the mouse click event to the holder.

      holder.addEventListener(MouseEvent.CLICK, holderHandler);

       

       

      //This function changes the colour of the movie clip inside

      //holder when it is clicked.

      function holderHandler (e:MouseEvent):void {

         for (var i:int = 0; i < holder.numChildren; i++) {

             if (holder.getChildAt(i).hitTestPoint(mouseX,mouseY,true)) {

                 colorTrans.color=colorArray[currentColor];

                 holder.getChildAt(i).transform.colorTransform=colorTrans;

             }

         }

      }

        • 1. Re: Change cursor color
          Peter Celuch Level 4

          If you want to change the color of the cursor, you should be setting its colorTransform:

           

          var trans:ColorTransform = new ColorTransform();
          trans.color = 0xFF0000; // any color you want
          m.transform.colorTransform = trans;
          

           

          You are setting color to object being clicked (holder) instead of coloring the cursor.

          1 person found this helpful
          • 2. Re: Change cursor color
            Owen_Alextoys Level 1

            That's close but not quite what I'm looking for. I'm trying to get the cursor to change to the color of the last object clicked in the color array.

             

             

            var trans:ColorTransform = new ColorTransform();

            trans.color=colorArray[currentColor]; // any color you want

            m.transform.colorTransform = trans;

             

             

            I tired this but it only picks up the first color in the array and dosen't change when I click the next one.

            • 3. Re: Change cursor color
              Peter Celuch Level 4

              That's strange. Try tracing few things to make sure everything works as it should:

               

              function ovalsClick(e:MouseEvent):void {
                   currentColor = e.currentTarget.arrayIndex;
              
                   trace(e.currentTarget, currentColor, colorArray[currentColor]);
              
                   var trans:ColorTransform = new ColorTransform();
                   trans.color = colorArray[currentColor];
                   m.transform.colorTransform = trans;
              }
              
              • 4. Re: Change cursor color
                Owen_Alextoys Level 1

                Okay that worked. Thanks.

                 

                -Owen