1. 我要改变影片的对齐方式

使用stage.align属性

stage.align的值是flash.display.StageAlign类的一个枚举。其值如下:

Value Vertical Alignment Horizontal
StageAlign.TOP Top Center
StageAlign.BOTTOM Bottom Center
StageAlign.LEFT Center Left
StageAlign.RIGHT Center Right
StageAlign.TOP_LEFT Top Left
StageAlign.TOP_RIGHT Top Right
StageAlign.BOTTOM_LEFT Bottom Left
StageAlign.BOTTOM_RIGHT Bottom Right
package
{flash.display.Sprite;flash.display.StageAlign;flash.display.StageScaleMode;Sample1105Sprite{Sample1105(){stage.scaleMode = StageScaleMode.NO_SCALE;stage.align = StageAlign.TOP_RIGHT;.graphics.beginFill(0xFF0000);.graphics.drawRect(10,10,stage.stageWidth,stage.stageHeight);.graphics.endFill();            }}
}

2. 确定客户端是否能播放音频

使用flash.system.Capabilities的hasAudio判断是否支持音频,hasMP3判断是否能播放MP3

(flash.system.Capabilities.hasAudio && flash.system.Capabilities.hasMP3)
{
}
else
{
}

3. 提示用户改变播放器设置

使用flash.system.Security.showSettings()方法打开用户的Flash播放器设置对话框窗口

该方法接受一个flash.system.SecurityPanel枚举作为参数。对应功能如下:

SecurityPanel.DEFAULT 默认面板

SecurityPanel.CAMERA 摄像头面板

SecurityPanel.LOCAL_STORAGE 本地存储面板

SecurityPanel.MICROPHONE 话筒面板

SecurityPanel.PRIVACY 安全控制面板

SecurityPanel.SETTINGS_MANAGER 管理面板会打开浏览器进行更多设置

 {flash.display.Sprite;flash.system.Security;flash.system.SecurityPanel;Sample1117Sprite{Sample1117(){flash.system.Security.showSettings(flash.system.SecurityPanel.DEFAULT);}}
}

4. 对数值进行四舍五入或取近似值

用Math.round()进行四舍五入,Math.floor()和Math.ceil()进行上下近似值。NumberUtilities.round()方法可自定义取值

 {ascb.util.NumberUtilities;flash.display.Sprite;Sample1117Sprite{Sample1117(){(Math.round(234.56)); (Math.floor(234.56)); (Math.ceil(234.56));  (Math.round(123.456*100)/100);(Math.round(123.456/0.1)*0.1);(NumberUtilities.round(123.456,0.1)); (NumberUtilities.round(123.456,6));   }}
}

5. 对数字和字符串进行格式化

用NumberFormat对象的format()与currencyFormat()方法。由于是第三方类库,测试过程中发现有些不完善。自己写了一个格式化货币的方法

 {flash.display.Sprite;Sample1118Sprite{Sample1118(){money:Number = 26591234569.5678;(formatString(money));i:int = 1234;(formatString(i));(formatString());}formatString(obj:Object):String{(obj    int||obj    uint||obj    Number){money:Number = obj    Number;str:String = (Math.round(money/0.01) * 0.01).toString();_index:int = str.indexOf();cursor:int = 0;(_index>-1){cursor = _index;str = str.substring(0,_index + 3);(str.length < _index+3){str = str + ;}           }else{cursor = str.length;str = str+;}arrStr:Array = Array();(cursor-3>=0){arrStr.push(str.substr(cursor-3,3));cursor = cursor-3;}(cursor>0){arrStr.push(str.substr(0,cursor));}arrStr.reverse();arrStr.join(',') + str.substr(str.indexOf());}else{obj.toString();}}   }
}

6. 生成随机数(猜硬币)

用NumberUtilities.random(0,1)方法产生随机数

 {ascb.util.NumberUtilities;flash.display.Sprite;flash.events.MouseEvent;flash.text.TextField;Sample1118Sprite{   label:TextField;Sample1118(){label = TextField();label.background = ;label.backgroundColor = 0xFF0000;label.textColor = 0xF7FCFF;label.autoSize = ;.addChild(label);sprite:Sprite = Sprite();sprite.graphics.beginFill(0xFFFF00);sprite.graphics.drawCircle(100,100,50);sprite.graphics.endFill();sprite.addEventListener(MouseEvent.CLICK,OnClick);.addChild(sprite);}OnClick(event:MouseEvent):{(NumberUtilities.random(0,1)==0){label.text = ;}else{label.text = ;}}}
}

7. 生成随机数(骰子)

用NumberUtilities.random(1,6)方法产生随机数

 {ascb.util.NumberUtilities;flash.display.Sprite;flash.events.MouseEvent;Sample1119Sprite{   sprite:Sprite;Sample1119(){sprite = Sprite();.addChild(sprite);sprite.addEventListener(MouseEvent.CLICK,OnClick);OnClick(null);  }OnClick(event:MouseEvent):{sprite.graphics.clear();sprite.graphics.beginFill(0xFFFFFF);sprite.graphics.drawRect(0,0,50,50);sprite.graphics.endFill();randNum:int = NumberUtilities.random(1,6);sprite.graphics.beginFill(0x000000);(randNum==1){       sprite.graphics.drawCircle(25,25,6);}else (randNum!=2){sprite.graphics.drawCircle(8,8,6);sprite.graphics.drawCircle(42,42,6);}(randNum==3||randNum==5){sprite.graphics.drawCircle(25,25,6);                }(randNum==4||randNum==5||randNum==6){sprite.graphics.drawCircle(42,8,6); sprite.graphics.drawCircle(8,42,6);}(randNum==2){sprite.graphics.drawCircle(25,8,6);sprite.graphics.drawCircle(25,42,6);            }(randNum==6){sprite.graphics.drawCircle(8,25,6);sprite.graphics.drawCircle(42,25,6);}sprite.graphics.endFill();}}
}

8. 生成唯一随机数(基于毫秒)

调用NumberUtilities.getUnique()得到当前时间(精确到毫秒)的唯一数字

 {ascb.util.NumberUtilities;flash.display.Sprite;Sample1119Sprite{   Sample1119(){(i:uint=0;i<10;i++){(NumberUtilities.getUnique());}}}
}

9. 计算两点之间的距离

根据勾股定理,使用Math.pow()和Math.sqrt()联合计算

 {   flash.display.Sprite;flash.geom.Point;Sample1119Sprite{   Sample1119(){p1:Point = Point(10,20);p2:Point = Point(100,200);x:int = p1.x - p2.x;y:int = p1.y = p2.y;length:Number = Math.sqrt(Math.pow(x,2)+Math.pow(y,2));(length);}}
}

10. DisplayObject类结构图

flash.display包中包含Flash Player用于构建可视显示内容的核心类。DisplayObject类是可放在显示列表中的所有对象的基类

转载于:https://www.cnblogs.com/CoderWayne/archive/2010/07/15/1778036.html

AS3 CookBook学习整理(二)相关推荐

  1. AS3 CookBook学习整理(八)

    1. AS3的事件机制 事件流机制即为捕获--目标--冒泡,分别对应event.eventPhase的值1(EventPhase.CAPTURING_PHASE),2(EventPhase.AT_TA ...

  2. AS3 CookBook学习整理(十七)

    1. 下载文件 使用flash.net.FileReference对象的download(urlRequest, aliasName)方法 download()方法最好在try...catch语句中执 ...

  3. AS3 CookBook学习整理(一)

    1. 我要改变swf的尺寸和颜色 在flex builder 3里,默认会生成一个全屏.背景色为#869CA7.帧数为24/秒的swf文件,要修改这些参数,只需要在类文件中定义 [SWF(width= ...

  4. java8学习整理二

    java8不但可以提高代码的运行的性能,而且实现起来很优雅,因此学习它是不错的选择. 今天写这篇文章,是因为看到我们部门大佬写的代码,因此将其还原成匿名内部类的时候发现这个retrun是不能省掉的,省 ...

  5. Deep Learning(深度学习)学习笔记整理(二)

    本文整理了网上几位大牛的博客,详细地讲解了CNN的基础结构与核心思想,欢迎交流 [1]Deep learning简介 [2]Deep Learning训练过程 [3]Deep Learning模型之: ...

  6. Bash Cookbook 学习笔记 【高级】

    Read Me 本文是以英文版<bash cookbook> 为基础整理的笔记,力求脱水 [高级]部分,涉及脚本安全.bash定制.参数设定等高阶内容 本系列其他两篇,与之互为参考 [基础 ...

  7. ACM竞赛学习整理开篇之01背包问题

    ACM竞赛学习整理开篇之01背包问题. 最近,偶然的一次机会让我关注信息奥赛的一些内容.发现其中的内容很有趣,是学习编程的一条很好的路径,又能很好地将数学和编程联系到一起.在csdn里看到了不少同好也 ...

  8. 2019.08.08学习整理

    2019.08.08学习整理 文件的高级应用 1.可读.可写 r+t: 可读.可写 w+t: 可写.可读 a+t: 可追加.可读 # wt with open('36w.txt', 'wt', enc ...

  9. Bash Cookbook 学习笔记 【中级】

    Read Me 本文是以英文版<bash cookbook> 为基础整理的笔记,力求脱水 2018.01.21 更新完[中级].内容包括工具.函数.中断及时间处理等进阶主题. 本系列其他两 ...

  10. 【Cocos2d-x for WP8 学习整理】(2)Cocos2d-Html5 游戏 《Fruit Attack》 WP8移植版 开源...

    [Cocos2d-x for WP8 学习整理](2)Cocos2d-Html5 游戏 <Fruit Attack> WP8移植版 开源 原文:[Cocos2d-x for WP8 学习整 ...

最新文章

  1. Oracle维护常用SQL语句
  2. C++非类型模板参数
  3. redis实现轮询算法_用redis实现支持优先级的消息队列
  4. ubuntu 12.04lts 安装insight6.8a
  5. Algorithm:C++语言实现之队列相关算法(最短路径条数问题、拓扑排序)
  6. 类似wordpress的网站模板
  7. SQLServer常用系统视图
  8. mysql中字符串和数字的互转函数
  9. 如何从0到1进行电商平台订单系统的搭建?
  10. php AES加解密
  11. java判断日期是否是同一周_java中如何判断两个日期是否是同一周
  12. 实验一 路由器的基本管理
  13. 怎么申请注册微信小程序-微信小程序教程1
  14. XML文件的一些操作
  15. linux环境nginx从下载到安装
  16. 「解决方案」预付费水电集团物业解决方案
  17. 数据结构(python) —— 【29: 贪心算法之换钱问题】
  18. 【无标题】Java实现进度条代码
  19. 工艺参数对铝合金热轧过程中亚晶粒大小形成的影响
  20. 寿光菜博会2021年元旦贺词 对话中国农民丰收节交易会

热门文章

  1. nth-of-type和nth-child的区别
  2. ModelSim SE 6.5破解
  3. Godaddy域名使用说明
  4. Windows基本的数据类型
  5. System76 是如何打造开源硬件的
  6. JAVA时间格式处理工具类
  7. 触发器、作业、序列、连接
  8. 十个必备的学习iOS开发的网站
  9. 1.看板方法---解决敏捷管理者的困境
  10. 153. php 引用