我想限制警報框到特定的模塊,它不應該在模塊範圍之外。我保留了2個包含不同模塊的標籤。但警戒的範圍正在全球化,除了限制到模塊區域之外,它正在影響整個窗口。 請看下面的代碼。限制警告框/彈出到flex中的inidvdual模塊3
main.mxml
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute">
<mx:Script>
<![CDATA[
import mx.modules.*;
public function createModule(m:ModuleLoader, s:String):void {
if (!m.url) {
m.url = s;
return;
}
m.loadModule();
}
public function removeModule(m:ModuleLoader):void {
m.unloadModule();
}
]]>
</mx:Script>
<mx:Panel title="Module Example"
height="90%"
width="90%"
paddingTop="10"
paddingLeft="10"
paddingRight="10"
paddingBottom="10"
>
<mx:TabNavigator id="tn"
width="100%"
height="100%"
creationPolicy="auto">
<mx:VBox id="vb1" label="Column Chart Module">
<mx:Button
label="Load" click="createModule(chartModuleLoader, l1.text)"/>
<mx:Button
label="Unload" />
<mx:Label id="l1" text="module1.swf"/>
<mx:ModuleLoader id="chartModuleLoader"/>
</mx:VBox>
<mx:VBox id="vb2" label="Form Module">
<mx:Button
label="Load" click="createModule(formModuleLoader, l2.text)"/>
<mx:Button
label="Unload"/>
<mx:Label id="l2" text="module2.swf"/>
<mx:ModuleLoader id="formModuleLoader"/>
</mx:VBox>
</mx:TabNavigator>
</mx:Panel>
</mx:Application>
Module1.mxml
<?xml version="1.0" encoding="utf-8"?>
<mx:Module xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" width="400" height="300">
<mx:Button label="Click 1 " click="ini()"/>
<mx:Script>
<![CDATA[
import mx.controls.Alert;
public function ini():void
{
Alert.show("How","hello", 0,null,null,null,0);
}
]]>
</mx:Script>
</mx:Module>
Module2.mxml
<?xml version="1.0" encoding="utf-8"?>
<mx:Module xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" width="400" height="300">
<mx:Button label="Click 2 " click="ini1()"/>
<mx:Script>
<![CDATA[
import mx.controls.Alert;
public function ini1():void
{
Alert.show("Click 2","hello", 0,this);
}
]]>
</mx:Script>
</mx:Module>
謝謝
這就是Alert.show的工作原理。它會在根應用程序級別創建一個警報。指定「父級」的唯一的事情就是告訴flex如何將警報集中在一起。如果你想要一個警報消失,當你改變標籤到另一個模塊,並且只有當模塊可見時纔可見(我認爲這就是你以後的樣子),那麼你將需要創建一個自定義組件,看起來像一個警報,你可以覆蓋代碼而不是使用Alert類。 –
你能否給我一個小的自定義類作爲例子,以便我可以得到一個更好的主意開始。提前致謝。 – user1647017
現在我想多了一點,你可以使用PopUpManager。我會在答案中提供代碼 –