3 Replies Latest reply on Jun 6, 2006 1:54 PM by Newsgroup_User

    Change a Labels Style

    slikone27
      I was wondering if anyone can help me out. I am trying to change a style of a label dynamically. The problem is I get an error "Call Attempted on an object that is not a function" if I try to define the var as an object and it doesn't work correctly as a string (even with [] since they killed the eval function).

      This works fine:
      lblHome.setStyle("color", "#FFFFFF")

      When I try to do it dynamically is when I get the error:
      private function itemOver(event:MouseEvent) : void
      {
      var itemID:Object = event.currentTarget.id;
      itemID.setStyle("color", "#FFFFFF") --- When I debug itemID is defined as lblHome
      }

      When I try to eval a string it changes style for all labels for some reason:
      private function itemOver(event:MouseEvent) : void
      {
      var itemID:String = event.currentTarget.id;
      [itemID]setStyle("color", "#FFFFFF") --- When I debug itemID is defined as lblHome
      }

      Can someone please help me... I am new to flex and trying to redo a ColdFusion flash forms app.

      Thanks
        • 1. Re: Change a Labels Style
          Level 7
          sloan2b wrote:

          > private function itemOver(event:MouseEvent) : void
          > {
          > var itemID:Object = event.currentTarget.id;
          > itemID.setStyle("color", "#FFFFFF") --- When I debug itemID is
          > defined as lblHome
          > }

          I think the problem is that itemID is actually the literal string
          "lblHome", not the label whose id is "lblHome". You probably want to do
          this instead:

          var item: Object = event.currentTarget;
          item.setStyle("color", "#FFFFFF");

          --
          nj
          Flex Builder team
          • 2. Re: Change a Labels Style
            slikone27 Level 1
            Thanks that did the trick... I should have thought of that, I guess I am just used to using eval(). I think I read somewhere else, but is there a problem w/ getting the hand cursor to display? I set useHandCursor="true" and I dont get the hand cursor over the label? Will this be fixed in the next version?
            • 3. Re: Change a Labels Style
              Level 7
              sloan2b wrote:
              > I think I read somewhere else, but is there a problem w/
              > getting the hand cursor to display? I set useHandCursor="true" and I dont get
              > the hand cursor over the label? Will this be fixed in the next version?

              useHandCursor is not supported for Label (it's a documentation bug that they
              are listed there). But you can use <mx:LinkButton> instead (and you can
              change its styles, as desired, to make it look more like a Label if you want to.)

              By the way, on those controls that *do* support useHandCursor, don't forget to
              also set buttonMode="true".


              --
              Mike Morearty
              Developer, Flex Builder team
              http://www.morearty.com/blog