4 Replies Latest reply on Feb 10, 2011 4:25 AM by Ibarim

    different cursors

    Ibarim Level 1

      Hi,

      I'm making a game and I want to use 3 cursors (every one in different color, e.g. green, red and black). One of the game options is cursor size, so I got big, medium and small cursor. This option is set once on the beggining of a game. So totaly there are 9 cursors (3 colors x 3 size). I made 9 cursors in flash and imported them with [Embed...] statement like this:

       

      [Embed(source="cursors.swf", symbol="cursor_small_green")]
      [Bindable] 
      private var cursor_small_green:Class;
      [Embed(source="cursors.swf", symbol="cursor_small_red")]
      [Bindable] 
      private var cursor_small_red:Class;
      etc....
      

       

      Everytime the cursor is supposed to change I have to write if statement for checking cursor size:

       

      if (cursorSize == "Small") {
         cursorMenager.setCursor(cursor_small_green)
      } else if (cursorSize == "Meidum") {
         cursorMenager.setCursor(cursor_medium_green)
      } else if (cursorSize == "Big") {
         cursorMenager.setCursor(cursor_big_green)
      }
      

       

      I would like to avoid this 'if' statement becouse cursor changes many times during a game. I would like to set cursor size once and for all when game begins. Something like this:

       

       

      if (cursorSize == "Small") {
      [Embed(source="cursors.swf", symbol="cursor_small_green")]
       [Bindable] 
       private var cursor_green:Class;
      } else if (cursorSize == "Medium") {
      [Embed(source="cursors.swf", symbol="cursor_medium_green")]
      [Bindable] 
      private var cursor_green:Class;
      } else if (cursorSize == "Big") {
      [Bindable]
      private var cursor_green:Class;
      }
      

       

      So during the game I could only use 'cursorManager.setCursor(cursor_green)'. But above syntax is wrong and I can't think of anything working similar to this.

       

      I was also thinking about cursorID. Something like this:

       

      private var cursorIdGreen:int
      private var cursorIdRed:int
      private var cursorIdBlack:int
      
      if (cursorSize == "Small") {
         cursorIdGreen = cursorMenager.setCursor(cursor_small_green)
         cursorIdRed = cursorManager.setCursor(cursor_small_red)
         curosrIdBlack = cursorManger.setCursor(cursor_small_black)
      } else if (cursorSize == "Medium") {.....etc....
      
      

      So during the game I would use 'cursorManager.currenCursorID = cursorIdGreen', but it's not possible to set cursor by it's ID (although it's possible to remove it by using ID).

       

      So I'm out of ideas how to solve this, any help please!

        • 1. Re: different cursors
          dataxa

          Why dont you make only 1 swf containing all the cursors you need on different frames (using Flash Professional). Then just use gotoAndStop(frameNr) to change cursor in flex. Or you can also make an array of cursor elements if you want to import all cursors seperatley and use index position to change cursors.

          • 2. Re: different cursors
            Ibarim Level 1

            Ad 1:

             

            I'm not sure how to change frame number, becouse serCursor method requires a class parameter and the gotoAndStop method is available only for object of a class.

            So when I try this:

             

            var cursor:swfCursor = new swfCursor;

            cursor.gotoAndStop(2);

            cursorManager.setCursor(cursor)

             

            it gives an error on the third line.

             

            Ad 2:

             

            I'll try to make an array and let know if it works.

            • 3. Re: different cursors
              Ibarim Level 1

              Ok,

               

              the array solution works. Thak you for help.

               

              Although the first solution with one symbol with many frames would be a better one, but still I'm not sure how use it.

              • 4. Re: different cursors
                dataxa Level 1

                Yes it would be better one but the issue there would be how to get instance of cursor class which is created by cursorManager and that i dont know. I saw that setCursor only returns id of cursor not not the instance itself. Maybe there is a mehtod which returns cursor instance via id.