Flex锁定页面遮罩【原创】
主要实现功能是锁定父页面,然后给出友好提示
效果图如下:
Mxml
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
layout="absolute"
verticalScrollPolicy="off"
horizontalScrollPolicy="off"
xmlns:Masks="Masks.*">
<mx:Script>
<![CDATA[
import mx.controls.Alert;
private function myClickFunction():void
{
new MyMasks(canvasTest);
}
]]>
</mx:Script>
<mx:Button x="150"
y="10"
label="Button"
click="myClickFunction();"/>
<mx:Canvas id="canvasTest"
backgroundColor="#110E0E"
x="215"
y="132"
width="214"
height="137">
<mx:Button x="74"
y="53"
label="Button"
click="Alert.show('test');"/>
</mx:Canvas>
</mx:Application>
MyMasks
package Masks
{
import flash.display.DisplayObject;
import mx.containers.Canvas;
import mx.containers.HBox;
import mx.controls.SWFLoader;
import mx.controls.Text;
public class MyMasks extends Canvas
{
public function MyMasks(obj:DisplayObject)
{
super();
var canvas:Canvas=obj as Canvas;
var arr:Array = canvas.getChildren();
for(var i:int=0;i<arr.length;i++)
{
if(arr[i] is MyMasks)
{
arr[i].visible = !arr[i].visible;
return;
}
}
this.setStyle("backgroundColor", "#FFFFFF");
this.setStyle("backgroundAlpha", 0);
this.width=canvas.width;
this.height=canvas.height;
var hbox:HBox=new HBox();
hbox.setStyle("width", "100%");
var swfLoader:SWFLoader=new SWFLoader();
swfLoader.source="../assets/loader.swf";
swfLoader.autoLoad=true;
var text:Text=new Text();
text.setStyle("color", "#ffffff");
text.text="正在加载...";
hbox.addChild(swfLoader);
hbox.addChild(text);
this.addChild(hbox);
this.id="mask";
canvas.addChild(this);
}
}
}