flex PopUpManager类
PopUpManager 类 PopUpManager 类ActionScript 类名称mx.managers.PopUpManager
PopUpManager 类的方法摘要
PopUpManager.createPopUp() 创建弹出窗口。
PopUpManager.deletePopUp() 删除由调用PopUpManager.createPopUp() 而创建的弹出窗口。
PopUpManager.createPopUp(parent, class, modal [, initobj, outsideEvents])
参数:parent 对弹出窗口所基于的窗口的引用。
class 对要创建的对象的类的引用。
modal 一个布尔值,它指示该窗口是(true) 否(false) 是模式
initobj 一个包含初始化属性的对象。此参数是可选的。
outsideEvents 一个布尔值,指示在用户单击窗口以外的区域时是(true) 否(false) 触发事件。此参数是可选的。
1.PopUpManager--createPopUp与addPopUp区别
createPopUp:是上来先设置好弹出方式,然后在new出来一个TitleWindow的对象,然后通过此对象设置他的变现形式。
addPopUp:是先new出来对象,设置好表现形式,然后在选择弹出来的方式。
一定要注意new对象与弹出方式的先后顺序。
addPopUp代码
1.<?xml version="1.0" encoding="utf-8"?>
2.<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
3. layout="vertical"
4. verticalAlign="middle"
5. backgroundColor="white"
6. creationComplete="init()">
7.
8. <mx:Script>
9. <![CDATA[
10. import mx.controls.Label;
11. import mx.events.CloseEvent;
12. import mx.containers.TitleWindow;
13. import mx.managers.PopUpManager;
14.
15. private var titleWindow:TitleWindow;
16.
17. private function init():void {
18. var label:Label = new Label();
19. label.text = "Hello world";
20.
21. titleWindow = new TitleWindow();
22. titleWindow.title = "Custom title";
23. titleWindow.showCloseButton = true;
24. titleWindow.width = 240;
25. titleWindow.height = 180;
26. titleWindow.addEventListener(CloseEvent.CLOSE, titleWindow_close);
27. titleWindow.addChild(label);
28.
29. PopUpManager.addPopUp(titleWindow, this, true);
30. PopUpManager.centerPopUp(titleWindow);
31. }
32.
33. private function titleWindow_close(evt:CloseEvent):void {
34. PopUpManager.removePopUp(titleWindow);
35. }
36. ]]>
37. </mx:Script>
38.
39. <mx:Button label="Launch TitleWindow" click="init()" />
40.
41.</mx:Application>
createPopUp代码:
1.<?xml version="1.0" encoding="utf-8"?>
2.<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
3. layout="vertical"
4. verticalAlign="middle"
5. backgroundColor="white"
6. creationComplete="init()">
7.
8. <mx:Script>
9. <![CDATA[
10. import mx.managers.PopUpManagerChildList;
11. import mx.controls.Label;
12. import mx.events.CloseEvent;
13. import mx.containers.TitleWindow;
14. import mx.managers.PopUpManager;
15.
16. private var titleWindow:TitleWindow;
17.
18. private function init():void {
19. var label:Label = new Label();
20. label.text = "Hello world";
21. titleWindow = new TitleWindow();
22. titleWindow = TitleWindow(PopUpManager.createPopUp(this,TitleWindow,true));
23. titleWindow.title = "Custom title";
24. titleWindow.showCloseButton = true;
25. titleWindow.width = 240;
26. titleWindow.height = 180;
27. titleWindow.addChild(label);
28. titleWindow.addEventListener(CloseEvent.CLOSE, titleWindow_close);
29. PopUpManager.centerPopUp(titleWindow);
30. }
31.
32. private function titleWindow_close(evt:CloseEvent):void {
33. PopUpManager.removePopUp(titleWindow);
34. }
35. ]]>
36. </mx:Script>
37.
38. <mx:Button label="Launch TitleWindow" click="init()" />
39.
40.</mx:Application>
2.弹出窗口为DataGrid添加新数据
(1)Note.as
package
{
public class Note
{
public var author:String;
public var topic:String;
public var description:String;
}
}
(2)AddNote.mxml
<?xml version="1.0" encoding="utf-8"?>
<mx:TitleWindow xmlns:mx="http://www.adobe.com/2006/mxml"
layout="absolute" width="348" height="218"
title="Add A Note">
<mx:Metadata>
[Event(name="SaveNote")]
</mx:Metadata>
<mx:Script>
<![CDATA[
import mx.managers.PopUpManager;
//PopUpManager.createPopUp() 创建弹出窗口
private function close():void
{
PopUpManager.removePopUp(this);
}
private function save():void
{
this.dispatchEvent(new Event("SaveNote"));
}
]]>
</mx:Script>
<mx:Label text="Author" x="35" y="10"/>
<mx:TextInput id="author" width="150" x="84" y="8"/>
<mx:Label text="Topic" y="36" x="42"/>
<mx:TextInput id="topic" width="150" x="84" y="34"/>
<mx:Label text="Description" y="62" x="10"/>
<mx:TextArea id="description" width="234" height="77" x="84" y="61"/>
<mx:Button label="Cancel" click="close()" x="193" y="146"/>
<mx:Button label="Save" click="save()" x="264" y="146"/>
</mx:TitleWindow >
(3)Test.mxml
<?xml version="1.0" encoding="utf-8"?>
<mx:Application
xmlns:mx="http://www.adobe.com/2006/mxml"
layout="absolute"
width="500" height="300"
creationComplete="init()">
<mx:Script>
<![CDATA[
import mx.managers.PopUpManager;
import mx.collections.ArrayCollection;
[Bindable]
private var notes:ArrayCollection = new ArrayCollection();
private var addNoteScreen:AddNote;
private function init():void
{
addNoteScreen = new AddNote();
addNoteScreen.addEventListener("SaveNote", saveNote);
}
private function addNote():void
{
PopUpManager.addPopUp(addNoteScreen, this, true);
PopUpManager.centerPopUp(addNoteScreen);
addNoteScreen.author.text = "";
addNoteScreen.topic.text = "";
addNoteScreen.description.text = "";
}
private function saveNote(e:Event):void
{
var note:Note = new Note();
note.author = addNoteScreen.author.text;
note.topic = addNoteScreen.topic.text;
note.description = addNoteScreen.description.text;
notes.addItem(note);
PopUpManager.removePopUp(addNoteScreen);
}
]]>
</mx:Script>
<mx:Panel title="Notes"
width="100%" height="100%"
layout="vertical" horizontalAlign="right"
paddingTop="3" paddingLeft="3" paddingRight="3" paddingBottom="3">
<mx:DataGrid dataProvider="{notes}" width="100%" height="100%">
<mx:columns>
<mx:DataGridColumn headerText="Author" dataField="author" width="80"/>
<mx:DataGridColumn headerText="Topic" dataField="topic" width="100"/>
<mx:DataGridColumn headerText="Description" dataField="description"/>
</mx:columns>
</mx:DataGrid>
<mx:Button label="Add Note" click="addNote()"/>
</mx:Panel>
</mx:Application>
PopUpManager 类 PopUpManager 类ActionScript 类名称mx.managers.PopUpManager
PopUpManager 类的方法摘要
PopUpManager.createPopUp() 创建弹出窗口。
PopUpManager.deletePopUp() 删除由调用PopUpManager.createPopUp() 而创建的弹出窗口。
PopUpManager.createPopUp(parent, class, modal [, initobj, outsideEvents])
参数:parent 对弹出窗口所基于的窗口的引用。
class 对要创建的对象的类的引用。
modal 一个布尔值,它指示该窗口是(true) 否(false) 是模式
initobj 一个包含初始化属性的对象。此参数是可选的。
outsideEvents 一个布尔值,指示在用户单击窗口以外的区域时是(true) 否(false) 触发事件。此参数是可选的。
1.PopUpManager--createPopUp与addPopUp区别
createPopUp:是上来先设置好弹出方式,然后在new出来一个TitleWindow的对象,然后通过此对象设置他的变现形式。
addPopUp:是先new出来对象,设置好表现形式,然后在选择弹出来的方式。
一定要注意new对象与弹出方式的先后顺序。
addPopUp代码
1.<?xml version="1.0" encoding="utf-8"?>
2.<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
3. layout="vertical"
4. verticalAlign="middle"
5. backgroundColor="white"
6. creationComplete="init()">
7.
8. <mx:Script>
9. <![CDATA[
10. import mx.controls.Label;
11. import mx.events.CloseEvent;
12. import mx.containers.TitleWindow;
13. import mx.managers.PopUpManager;
14.
15. private var titleWindow:TitleWindow;
16.
17. private function init():void {
18. var label:Label = new Label();
19. label.text = "Hello world";
20.
21. titleWindow = new TitleWindow();
22. titleWindow.title = "Custom title";
23. titleWindow.showCloseButton = true;
24. titleWindow.width = 240;
25. titleWindow.height = 180;
26. titleWindow.addEventListener(CloseEvent.CLOSE, titleWindow_close);
27. titleWindow.addChild(label);
28.
29. PopUpManager.addPopUp(titleWindow, this, true);
30. PopUpManager.centerPopUp(titleWindow);
31. }
32.
33. private function titleWindow_close(evt:CloseEvent):void {
34. PopUpManager.removePopUp(titleWindow);
35. }
36. ]]>
37. </mx:Script>
38.
39. <mx:Button label="Launch TitleWindow" click="init()" />
40.
41.</mx:Application>
createPopUp代码:
1.<?xml version="1.0" encoding="utf-8"?>
2.<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
3. layout="vertical"
4. verticalAlign="middle"
5. backgroundColor="white"
6. creationComplete="init()">
7.
8. <mx:Script>
9. <![CDATA[
10. import mx.managers.PopUpManagerChildList;
11. import mx.controls.Label;
12. import mx.events.CloseEvent;
13. import mx.containers.TitleWindow;
14. import mx.managers.PopUpManager;
15.
16. private var titleWindow:TitleWindow;
17.
18. private function init():void {
19. var label:Label = new Label();
20. label.text = "Hello world";
21. titleWindow = new TitleWindow();
22. titleWindow = TitleWindow(PopUpManager.createPopUp(this,TitleWindow,true));
23. titleWindow.title = "Custom title";
24. titleWindow.showCloseButton = true;
25. titleWindow.width = 240;
26. titleWindow.height = 180;
27. titleWindow.addChild(label);
28. titleWindow.addEventListener(CloseEvent.CLOSE, titleWindow_close);
29. PopUpManager.centerPopUp(titleWindow);
30. }
31.
32. private function titleWindow_close(evt:CloseEvent):void {
33. PopUpManager.removePopUp(titleWindow);
34. }
35. ]]>
36. </mx:Script>
37.
38. <mx:Button label="Launch TitleWindow" click="init()" />
39.
40.</mx:Application>
2.弹出窗口为DataGrid添加新数据
(1)Note.as
package
{
public class Note
{
public var author:String;
public var topic:String;
public var description:String;
}
}
(2)AddNote.mxml
<?xml version="1.0" encoding="utf-8"?>
<mx:TitleWindow xmlns:mx="http://www.adobe.com/2006/mxml"
layout="absolute" width="348" height="218"
title="Add A Note">
<mx:Metadata>
[Event(name="SaveNote")]
</mx:Metadata>
<mx:Script>
<![CDATA[
import mx.managers.PopUpManager;
//PopUpManager.createPopUp() 创建弹出窗口
private function close():void
{
PopUpManager.removePopUp(this);
}
private function save():void
{
this.dispatchEvent(new Event("SaveNote"));
}
]]>
</mx:Script>
<mx:Label text="Author" x="35" y="10"/>
<mx:TextInput id="author" width="150" x="84" y="8"/>
<mx:Label text="Topic" y="36" x="42"/>
<mx:TextInput id="topic" width="150" x="84" y="34"/>
<mx:Label text="Description" y="62" x="10"/>
<mx:TextArea id="description" width="234" height="77" x="84" y="61"/>
<mx:Button label="Cancel" click="close()" x="193" y="146"/>
<mx:Button label="Save" click="save()" x="264" y="146"/>
</mx:TitleWindow >
(3)Test.mxml
<?xml version="1.0" encoding="utf-8"?>
<mx:Application
xmlns:mx="http://www.adobe.com/2006/mxml"
layout="absolute"
width="500" height="300"
creationComplete="init()">
<mx:Script>
<![CDATA[
import mx.managers.PopUpManager;
import mx.collections.ArrayCollection;
[Bindable]
private var notes:ArrayCollection = new ArrayCollection();
private var addNoteScreen:AddNote;
private function init():void
{
addNoteScreen = new AddNote();
addNoteScreen.addEventListener("SaveNote", saveNote);
}
private function addNote():void
{
PopUpManager.addPopUp(addNoteScreen, this, true);
PopUpManager.centerPopUp(addNoteScreen);
addNoteScreen.author.text = "";
addNoteScreen.topic.text = "";
addNoteScreen.description.text = "";
}
private function saveNote(e:Event):void
{
var note:Note = new Note();
note.author = addNoteScreen.author.text;
note.topic = addNoteScreen.topic.text;
note.description = addNoteScreen.description.text;
notes.addItem(note);
PopUpManager.removePopUp(addNoteScreen);
}
]]>
</mx:Script>
<mx:Panel title="Notes"
width="100%" height="100%"
layout="vertical" horizontalAlign="right"
paddingTop="3" paddingLeft="3" paddingRight="3" paddingBottom="3">
<mx:DataGrid dataProvider="{notes}" width="100%" height="100%">
<mx:columns>
<mx:DataGridColumn headerText="Author" dataField="author" width="80"/>
<mx:DataGridColumn headerText="Topic" dataField="topic" width="100"/>
<mx:DataGridColumn headerText="Description" dataField="description"/>
</mx:columns>
</mx:DataGrid>
<mx:Button label="Add Note" click="addNote()"/>
</mx:Panel>
</mx:Application>