2 Replies Latest reply on Jan 14, 2011 2:33 AM by Wrataxas

    What's wrong with using "this" here?

    Wrataxas Level 2

      <?xml version="1.0" encoding="utf-8"?>
      <s:BorderContainer xmlns:fx="http://ns.adobe.com/mxml/2009" xmlns:s="library://ns.adobe.com/flex/spark" xmlns:mx="library://ns.adobe.com/flex/mx">
           <fx:Script>
                <![CDATA[
                     import mx.core.IVisualElementContainer;
                     public function set thingHolder(value:IVisualElementContainer):void
                         { _thingHolder = value; }
                     protected var _thingHolder:IVisualElementContainer = this;
                ]]>
           </fx:Script>
      </s:BorderContainer>
      
      

       

      The error I get on the "protected var ..." line is:

          1067: Implicit coercion of a value of type Class to an unrelated type mx.core:IVisualElementContainer.

       

      I want the object to initialize the thingHolder property to itself and also support the property being set to something else by the component that includes this one.

        • 1. Re: What's wrong with using "this" here?
          Gregory Lafrance Level 6

          This seems to work:

           

          <?xml version="1.0" encoding="utf-8"?>
          <s:BorderContainer xmlns:fx="http://ns.adobe.com/mxml/2009" 
                             xmlns:s="library://ns.adobe.com/flex/spark" 
                             xmlns:mx="library://ns.adobe.com/flex/mx">
            <fx:Script>
              <![CDATA[
                import mx.core.IVisualElementContainer;
                public function set thingHolder(value:IVisualElementContainer):void
                { _thingHolder = value; }
                protected var _thingHolder:IVisualElementContainer = IVisualElementContainer(this);
              ]]>
            </fx:Script>
          </s:BorderContainer>
          

           

          If this post answers your question or helps, please mark it as such. Thanks!

          http://www.stardustsystems.com
          Adobe Flex Development and Support Services

          • 2. Re: What's wrong with using "this" here?
            Wrataxas Level 2

            The code compiles and runs fine with that change.  Thanks.