3 Replies Latest reply on Nov 9, 2010 7:45 AM by tehxike1

    factory items fail is Class test

    tehxike1 Level 1

      I have a factory defined in my skin file:

       

       

      <fx:Component id="radioButtonClass">

           <s:RadioButton />

      </fx:Component>

       

       

      I use this in my code:

       

      metaComp = radioButtonClass.newInstance();

       

      I later iterate over the items, attempting to perform actions on them based on their type:

       

      case ToggleButtonBase:

           //do stuff

           break;

       

      But every item shows up as the radioButtonClass.generator:

       

      com.levelsbeyond.search.skins.SearchPropertiesViewSkinInnerClass7 (@88f10a1)

       

      How can I do a class test against the object?  I'm trying this, but it doesn't work either:

       

      case (radioButtonClass as ClassFactory).generator:

       

      I'd love to be able to just check to see if something's a ToggleButtonBase, but that doesn't pass the is test.

        • 1. Re: factory items fail is Class test
          Shongrunden Adobe Employee

          Can you use className instead of id?  This seems to work:

           

          <s:Application xmlns:fx="http://ns.adobe.com/mxml/2009"
                         xmlns:s="library://ns.adobe.com/flex/spark"
                         creationComplete="init()">
              <fx:Script>
                  <![CDATA[
                      import spark.components.RadioButton;
                      private function init():void{
                          var myComponent:MyComponent = new MyComponent();
                         
                          if (myComponent is RadioButton)
                              test.text = 'pass';
                          else
                              test.text = 'fail';
                         
                      }

                  ]]>
              </fx:Script>
              <fx:Declarations>
                  <fx:Component className="MyComponent">
                      <s:RadioButton/>
                  </fx:Component>
              </fx:Declarations>
             
              <s:Label id="test" />
             
          </s:Application>

          • 2. Re: factory items fail is Class test
            Shongrunden Adobe Employee

            Actually it looks like using id works as well:


            <s:Application xmlns:fx="http://ns.adobe.com/mxml/2009"
                           xmlns:s="library://ns.adobe.com/flex/spark"
                           creationComplete="init()">
                <fx:Script>
                    <![CDATA[
                        import spark.components.supportClasses.ToggleButtonBase;
                        private function init():void{
                            var myComponent:Object = MyComponent.newInstance();
                           
                            if (myComponent is ToggleButtonBase)
                                test.text = 'pass';
                            else
                                test.text = 'fail';
                           
                        }

             

                    ]]>
                </fx:Script>
                <fx:Declarations>
                    <fx:Component id="MyComponent">
                        <s:RadioButton/>
                    </fx:Component>
                </fx:Declarations>
               
                <s:Label id="test" />
               
            </s:Application>

             

             

             

            1 person found this helpful
            • 3. Re: factory items fail is Class test
              tehxike1 Level 1

              Ah yeah, the is check is working for me too.  I'm not sure why it doesn't pass in the switch, but this will work fine.  Thanks