2011-07-29 55 views
1

我有一個公共變量組件訪問組件的屬性聲明從延長部件

[Bindable] 
public var mnuSource:String; 

當我擴展這個組件,我可以引用mnuSource(它編譯),但運行時抱怨不被訪問的屬性(錯誤1056)。

如何修改/聲明組件屬性,以便它們實際上可用於其他組件?

感謝

+1

你能發佈一些更多的原始和擴展組件的代碼嗎?您可以跳過該代碼中無關的細節。 – Constantiner

+1

你做得對;但顯示完整的錯誤和引發它的線形成你的子組件。 – JeffryHouser

回答

0

同The_asMan但在MXML

應用

<?xml version="1.0" encoding="utf-8"?> 
<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009" 
       xmlns:s="library://ns.adobe.com/flex/spark" xmlns:local="*" 
       > 
    <local:SomeExtendedComponent /> 
</s:Application> 

一些基礎組件

<?xml version="1.0" encoding="utf-8"?> 
<s:Group 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[ 
      [Bindable] 
      public var mnuSource:String; 
     ]]> 
    </fx:Script> 
    <fx:Declarations> 
     <!-- Place non-visual elements (e.g., services, value objects) here --> 
    </fx:Declarations> 
</s:Group> 

延長部件的

<?xml version="1.0" encoding="utf-8"?> 
<local:SomeBaseComponent xmlns:fx="http://ns.adobe.com/mxml/2009" 
         xmlns:s="library://ns.adobe.com/flex/spark" 
         xmlns:mx="library://ns.adobe.com/flex/mx" xmlns:local="*" 
         creationComplete="cc(event)"> 
    <fx:Script> 
     <![CDATA[ 
      import mx.controls.Alert; 
      import mx.events.FlexEvent; 

      protected function cc(event:FlexEvent):void 
      { 
       mnuSource = "Hi there!"; 
       Alert.show(mnuSource); 
      } 

     ]]> 
    </fx:Script> 
    <fx:Declarations> 
     <!-- Place non-visual elements (e.g., services, value objects) here --> 
    </fx:Declarations> 
    <s:Label text="{mnuSource}" /> 
</local:SomeBaseComponent> 
+0

你的代碼絕對好用! ) – grass

0

這是未經測試的代碼,但應該工作,並給你一個好主意,如何擴展一個類。

MyBaseClass.as 
package{ 
    public class MyBaseClass{ 
    public var someVar:String; 
    public function MyBaseClass()::void{ 
     this.someVar = 'set from MyBaseClass'; 
    } 
    } 
} 


MyBaseclassExtended.as 
package{ 
    public class MyBaseclassExtended extends MyBaseClass{ 
    public MyBaseclassExtended(){ 
     this.someVar = 'Set from MyBaseclassExtended'; 
    } 
    } 
} 


call it like so 
var asdf:MyBaseclassExtended = new MyBaseclassExtended(); 
trace(asdf.someVar) // Set from MyBaseclassExtended