4 Replies Latest reply on Dec 17, 2008 6:57 AM by nickname118

    Accessing styles of a component

    nickname118
      Forgive me if this has an obvious answer, but I am curious. How can I get an object or a list of all styles or CSSStyleDeclaration objects that will be applied to a component?

      Like say for a simple example I have a stylesheet "myStyles.css" in my project. And I set it in my component with the Style tag:

      <mx:Style source="myStyles.css" />

      How can I see inside the component what all the styles are that can be applied in that component?
      Like say I've made class selectors in my stylesheet, and in my app I want to know what styles they might have before I actually apply them to any objects. I'm not sure where the stylesheet lives when you add it this way, so I don't know how to go about finding it.
        • 1. Re: Accessing styles of a component
          Level 7

          "nickname118" <webforumsuser@macromedia.com> wrote in message
          news:ghuese$fe7$1@forums.macromedia.com...
          > Forgive me if this has an obvious answer, but I am curious. How can I get
          > an
          > object or a list of all styles or CSSStyleDeclaration objects that will be
          > applied to a component?
          >
          > Like say for a simple example I have a stylesheet "myStyles.css" in my
          > project. And I set it in my component with the Style tag:
          >
          > <mx:Style source="myStyles.css" />
          >
          > How can I see inside the component what all the styles are that can be
          > applied
          > in that component?
          > Like say I've made class selectors in my stylesheet, and in my app I want
          > to
          > know what styles they might have before I actually apply them to any
          > objects.
          > I'm not sure where the stylesheet lives when you add it this way, so I
          > don't
          > know how to go about finding it.

          Typically the way this is done is by overriding the setStyle function and
          setting a flag when "your" styles come in so that you can change them in
          updateDisplayList.

          HTH;

          Amy


          • 2. Re: Accessing styles of a component
            nickname118 Level 1
            No, meant a list of all available styles.

            For example, there is a property of StyleManager called selectors. This is an Array of all the available class and type selectors.

            But how do I get the actual styles out of that? There is a function StyleManager.getStyleDeclaration() that I can call for each selector in the array, but I don't know of a way to get at the actual styles inside each selector if I don't know them in advance. All the CSSStyleDeclaration class has is a method getStyle(), but it requires you to provide a name of that style. Surely there must be an array, or arrays somewhere that the CSSStyleDeclaration is checking to return the values for you.
            • 3. Re: Accessing styles of a component
              Level 7

              "nickname118" <webforumsuser@macromedia.com> wrote in message
              news:ghui7s$jkg$1@forums.macromedia.com...
              > No, meant a list of all available styles.
              >
              > For example, there is a property of StyleManager called selectors. This is
              > an
              > Array of all the available class and type selectors.
              >
              > But how do I get the actual styles out of that? There is a function
              > StyleManager.getStyleDeclaration() that I can call for each selector in
              > the
              > array, but I don't know of a way to get at the actual styles inside each
              > selector if I don't know them in advance. All the CSSStyleDeclaration
              > class has
              > is a method getStyle(), but it requires you to provide a name of that
              > style.
              > Surely there must be an array, or arrays somewhere that the
              > CSSStyleDeclaration
              > is checking to return the values for you.

              I'm not sure what it really gets you to try to go around the inbuilt method
              the Flex Engineers created for handling styling. Good luck, though.


              • 4. Re: Accessing styles of a component
                nickname118 Level 1
                I am building two versions of the same component. One in Flex, and the other in html, so that the user can print the content they are viewing.

                I had originally built a print preview page, but it was iffy at best. So we're just going to throw everything into an html page and open that in a new window when the user wants to print.

                I would have liked to keep my flex stylesheet, and use those values to assign to the html styles, but it looks like I need a separate one that I will have to maintain to make sure they match. Oh well.