做Flex Mobile开发的人应该知道,Flex为手机应用并没有提供弹出框组件,需要自定义。

通过查找文档、资料,我做出一个效果还算不错的弹出框组件,可以适用于手机设备上,不多讲,直接贴源码,相信对Flex了解的人都可以一看就懂。

首先,需要MXML定义弹出框组件:

<s:SkinnablePopUpContainer xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
xmlns:itemrenderer="com.adobe.mobilecrud.view.itemrenderer.*"
width="{screenX * 0.75}" height="{screenY * 0.25}" backgroundAlpha="0"
creationComplete="CenterPopUp()"
preinitialize="screen_initializeHandler(event)"> <fx:Script>
<![CDATA[
import mx.core.FlexGlobals;
import mx.events.FlexEvent; [Bindable]
public var title:String = "";
[Bindable]
public var message:String = ""; [Bindable]
private var screenX:Number;
[Bindable]
private var screenY:Number; // 使应用程序居中
private function CenterPopUp():void{
this.x = FlexGlobals.topLevelApplication.width / 2 - this.width / 2;
this.y = FlexGlobals.topLevelApplication.height / 2 - this.height / 2; }
// 初始化窗口大小
protected function screen_initializeHandler(event:FlexEvent):void
{
screenX = Capabilities.screenResolutionX;
trace("screenX:"+screenX);
screenY = Capabilities.screenResolutionY;
} ]]>
</fx:Script> <s:Rect width="100%" height="100%" radiusX="10" radiusY="10">
<s:stroke>
<s:SolidColorStroke color="#C2C6C3" weight="1"/>
</s:stroke>
<s:fill>
<s:SolidColor alpha="1.0" color="white"/>
</s:fill>
</s:Rect> <s:VGroup width="100%" height="100%" gap="0" paddingTop="1">
<s:Group width="100%" height="50">
<s:Rect width="100%" height="100%" radiusX="10" radiusY="10">
<s:fill>
<s:LinearGradient rotation="90">
<s:entries>
<s:GradientEntry color="#f9f8f6" ratio="0.00"/>
<s:GradientEntry color="#e3dfd7" ratio="0.60"/>
<s:GradientEntry color="#f7f6f2" ratio="1.00"/>
</s:entries>
</s:LinearGradient>
</s:fill>
</s:Rect>
<s:HGroup width="100%" height="100%" verticalAlign="middle">
<s:Image source="@Embed('assets/alert/w1.png')"/>
<s:Label color="#EE9F29" fontSize="30" fontWeight="bold" text="{title}"/>
</s:HGroup>
</s:Group> <s:Line width="100%">
<s:stroke>
<s:LinearGradientStroke caps="round" weight="1">
<s:entries>
<s:GradientEntry color="#c2bfad" ratio="0.5"/>
</s:entries>
</s:LinearGradientStroke>
</s:stroke>
</s:Line> <s:VGroup width="100%" height="50%" horizontalAlign="center" verticalAlign="middle">
<s:Label width="92%" height="100%" color="#5a5a5a" fontSize="25" lineBreak="toFit"
maxDisplayedLines="2" text="{message}" textAlign="center"
verticalAlign="middle"/>
</s:VGroup> <s:HGroup width="100%" color="#5a5a5a" fontSize="18" horizontalAlign="center">
<s:VGroup width="50%" horizontalAlign="center">
<s:Button id="btnOk" width="100" height="40" label="确 定" chromeColor="#e3dfd7"/>
</s:VGroup> <s:VGroup width="50%" horizontalAlign="center">
<s:Button id="btnCancel" width="100" height="40" label="取 消" chromeColor="#e3dfd7"/>
</s:VGroup> </s:HGroup>
</s:VGroup>
</s:SkinnablePopUpContainer>

组件定义成功后,我们可以写一个as文件,拿它来调用mxml文件:

package alert
{
import flash.display.DisplayObjectContainer;
import flash.events.MouseEvent; import mx.core.FlexGlobals; import spark.components.View;
import spark.events.PopUpEvent; public class Confirm
{
private static var confirm:Confirm = null; private var confirmView:AlertConfirmView = new AlertConfirmView(); private var closeHandler:Function = null; public static function getInstance():Confirm{
if(confirm == null){
confirm = new Confirm();
} return confirm;
} public function show(owner:DisplayObjectContainer,text:String = '',title:String = '', closeHandler:Function = null):void{
confirmView.title = title;
confirmView.message = text; confirmView.open(owner,true); if(closeHandler != null){
this.closeHandler = closeHandler;
//confirmView.addEventListener(PopUpEvent.CLOSE,closeHandler);
}else{ } confirmView.btnOk.addEventListener(MouseEvent.CLICK,btnClose_clickHandler);
confirmView.btnCancel.addEventListener(MouseEvent.CLICK,btnClose_clickHandler);
} // 处理按钮监听事件
protected function btnClose_clickHandler(event:MouseEvent):void
{
confirmView.btnOk.removeEventListener(MouseEvent.CLICK,btnClose_clickHandler);
confirmView.btnCancel.removeEventListener(MouseEvent.CLICK,btnClose_clickHandler); trace(event.currentTarget.id); if(event.currentTarget.id == 'btnOk'){
confirmView.addEventListener(PopUpEvent.CLOSE,closeHandler);
trace("YES");
}else{
trace("NO");
} confirmView.close();
}
// 取消PopUp监听
public function cancelMonitor():void{
confirmView.removeEventListener(PopUpEvent.CLOSE,closeHandler);
} }
}

其实,内容很简单,关于这方面的资料网上也是有一些的,但尽善尽美的东西却很少,我写的这个也算不得很完美,不过已经很实用了。

源代码下载地址:http://download.csdn.net/detail/zuiwuyuan/8020273

Flex AIR自定义Mobile的弹出框组件的更多相关文章

  1. 关于隐式创建vue实例实现简化弹出框组件显示步骤

    我们在使用vue写alert组件的时候,经常是定义了一个alert.vue,然后引入alert.vue,然后配置参数等等,非常繁琐,那有没有一种方式可以像window.alert("内容&q ...

  2. 基于Vue.js PC桌面端弹出框组件|vue自定义弹层组件|vue模态框

    vue.js构建的轻量级PC网页端交互式弹层组件VLayer. 前段时间有分享过一个vue移动端弹窗组件,今天给大家分享一个最近开发的vue pc端弹出层组件. VLayer 一款集Alert.Dia ...

  3. 自定义Bootstrap样式弹出框

    最近做的一些功能需要用到Bootstrap,然而原来的系统并没有引入Bootstrap,为了新写的控件能够应用于老的页面,又不需要在老的页面上引入全套的Bootstrap文件决定写一个模仿Bootst ...

  4. co-dialog弹出框组件-版本v2.0.1

    具体案例查看co-dialog:https://koringz.github.io/co-dialog/index.html 2.0.1版本优化项,代码压缩,修复PC和移动端自适应,修复显示弹出框浏览 ...

  5. co-dialog弹出框组件-版本v2.0.0

    co-dialog theme 访问git:co-dialog 版本v2.0.0 主题2 coog.app('.theme2').use({ title: 'JUST CHECKING.', mess ...

  6. ReactNative: 使用弹出框组件ActionSheetIOS组件

    一.简介 在上一篇文章中,详细介绍了对话框组件,除此之外,React-Native系统还给开发者提供了一个弹框框组件ActionSheetIOS组件,它的弹出方式与对框框不同,它是从底部弹出,与iOS ...

  7. 安卓开发之自定义一个view弹出框

    https://www.cnblogs.com/muyuge/p/6152167.html

  8. android自定义弹出框样式实现

    前言: 做项目时,感觉Android自带的弹出框样式比较丑,很多应用都是自己做的弹出框,这里也试着自己做了一个. 废话不说先上图片: 实现机制 1.先自定义一个弹出框的样式 2.自己实现CustomD ...

  9. UIPresentationController - iOS自定义模态弹出框

    参考: https://developer.apple.com/library/archive/featuredarticles/ViewControllerPGforiPhoneOS/Definin ...

随机推荐

  1. plotroc.m

    function out1 = plotroc(varargin) %PLOTROC Plot receiver operating characteristic. % % <a href=&q ...

  2. 集合-Map 接口

    1. 概述   java.util.Map <K,V>接口是一个顶层接口,里面存放的数据单元是:单对元素: K 表示 描述的键 的类型,Key 的类型: V 表示 描述的值 的类型,Val ...

  3. [J2EE规范]RMI简单实例 标签: j2ee实例 2017-06-29 18:05 217人阅读 评论(13)

    RMI是什么? RMI是指Java Remote Method Invocation,远程方法调用,RMI是Java的一组拥护开发分布式应用程序的API.RMI使用Java语言接口定义了远程对象,它集 ...

  4. php表单和缩略图处理类是什么样呢

    <?php//封装一个表单验证类//中文验证.邮箱验证.电话号码.手机.QQ.身份证.(由字母.数字.下划线组成,不能以数字开头)header('content-type:text/html;c ...

  5. CSS3圆环旋转效果

    html结构: <div class="demo"></div> css结构: .demo{ width:250px; height:250px; bord ...

  6. 云计算、大数据、编程语言学习指南下载,100+技术课程免费学!这份诚意满满的新年技术大礼包,你Get了吗?

    开发者认证.云学院.技术社群,更多精彩,尽在开发者会场 近年来,新技术发展迅速.互联网行业持续高速增长,平均薪资水平持续提升,互联网技术学习已俨然成为学生.在职人员都感兴趣的“业余项目”. 阿里云大学 ...

  7. SAS-一些有用的语句

    SAS-一些有用的语句 今天本想继续介绍 summary过程的,但是发现别人整理的比我更好,于是周末再更,好好整理一下描述性统计分析及评分卡建模,今天给大家介绍一些sas有用的语句吧. 1.如果在同一 ...

  8. 【水滴石穿】react-native-template-app

    这个也是一个基础项目 地址如下https://github.com/ndlonghi/react-native-template-app 点击登陆跳转到首页 分析代码如 react-native-te ...

  9. 通过反射 修改访问和修改属性的值 Day25

    package com.sxt.field; /* * 通过反射拿到属性值 * 修改public属性值 * 修改private属性值 * 缺点:可读性差:代码复杂 * 优点:灵活:可以访问修改priv ...

  10. 【Objective-C】-空指针和野指针

    一.什么是空指针和野指针 1.空指针 1> 没有存储任何内存地址的指针就称为空指针(NULL指针) 2> 空指针就是被赋值为0的指针,在没有被具体初始化之前,其值为0. 下面两个都是空指针 ...