package com.views
{ import flash.display.Bitmap;
import flash.display.MovieClip;
import flash.display.Sprite;
import flash.events.Event; /**
* @author:Frost.Yen
* @E-mail:871979853@qq.com
* @create: 2016-7-7 下午2:33:56
*
*/
public class LogoView extends Sprite
{
private var _stageW:Number = 1920;
private var _stageH:Number = 1080;
private var _mc:MovieClip = new MovieClip();
public function LogoView(bmp:Bitmap)
{
_mc.addChild(bmp);
bmp.x = -bmp.width*0.5;
bmp.y = -bmp.height*0.5;
initLogo();
} private function initLogo():void{ //随机位置
_mc.x = Math.random()*_stageW;
_mc.y = Math.random()*_stageH;
//随机速度和方向
Math.random()>0.5?_mc.speedX = Math.random()*5+1 : _mc.speedX = -1 * Math.random()*5+1
Math.random()>0.5?_mc.speedY = Math.random()*5+1 : _mc.speedY = -1 * Math.random()*5+1
//因为logo的坐标原点是logo的中心,所以用该函数用来调整logo位置,防止移出边界
adjustBall(_mc);
//添加logo到显示列表
addChild(_mc);
//用ENTER_FRAME侦听器使logo运动
//startMove();
} private function adjustBall(mc:MovieClip):void{
if(mc.x > _stageW-mc.width/2){mc.x = _stageW-mc.width/2;}
if(mc.x < mc.width/2){mc.x = mc.width/2};
if(mc.y > _stageH-mc.height/2){mc.y = _stageH-mc.height/2;}
if(mc.y < mc.height/2){mc.y = mc.height/2;}
} private function onEnterFrame(evt:Event):void{
//改变logo的坐标让小球运动
evt.target.x += evt.target.speedX;
evt.target.y += evt.target.speedY;
//检测logo是否碰到舞台边界
if(evt.target.x >= _stageW-evt.target.width/2 || evt.target.x <= evt.target.width/2){
evt.target.speedX *= -1;
}
if(evt.target.y >= _stageH-evt.target.height/2 || evt.target.y <= evt.target.height/2){
evt.target.speedY *= -1;
}
}
public function startMove():void
{
_mc.addEventListener(Event.ENTER_FRAME,onEnterFrame);
}
public function stopMove():void
{
_mc.removeEventListener(Event.ENTER_FRAME,onEnterFrame);
}
}
}

最新文章

  1. Time-travel Models
  2. Struts2登录小例子
  3. 《Java虚拟机并发编程》学习笔记
  4. [译] C track: compiling C programs.
  5. Tasks.Parallel
  6. kvm xxx.xml文件的位置
  7. Spring Cloud Eureka Server 启停状态监控
  8. ios开发者创建app应用开发授权文件 实战方法:
  9. BeagleBone Black 板第三课:Debian7.5系统安装和远程控制BBB板
  10. php sso 单点登录的实现 代码示例
  11. 导出含有图片的Java项目,图片不显示
  12. spring boot 2.0 ribbon 负载均衡配置
  13. MySQL 存储过程的变量
  14. ubuntu安装spyder和jupyter notebook
  15. 第26月第25天 ubuntu openjdk-8-jdk jretty
  16. 使用SpotBugs/FindBugs进行代码检查
  17. 还没被玩坏的robobrowser(8)——robobrowser的实现原理
  18. 【资源大全】.NET资源大全中文版(Awesome最新版)
  19. Find substring with K-1 distinct characters
  20. sql STUFF 分组

热门文章

  1. iOS开发网络篇—搭建本地服务器
  2. 对已经发布订阅的sqlserver进行修改-添加新的表
  3. solr windows 启动和关闭命令
  4. Hadoop1.2.1 全集群3节点安装-rpm安装
  5. 谈谈UIView的几个layout方法
  6. Xceed Ultimate Suite Xceed界面控件套包下载
  7. Divisors
  8. 团队开发——冲刺1.b
  9. SQLAlchemy一对多总结
  10. Mybatis-动态 SQL