5D艺术网首页
商城
|
资讯
|
作品
|
博客
|
教程
|
论坛
登录
注册
加为好友
发短消息
来自:
性别:秘密
最后登录:2007-04-12
http://Billows.5d.cn/
首页
|
新闻
|
话题
|
博客
|
相册
|
艺术作品
|
社交关系
|
留言板
|
社交圈
2006/09/19 | AS3实现openv的电视墙效果
类别(Flex&AS3)
|
评论
(0)
|
阅读(744)
|
发表于 15:38
今天看见demo.openv.tv的电视墙效果不错,于是用AS3实现了类似功能,就当用AS3练手了,呵呵。
代码如下:
package {
import flash.display.Sprite;
import flash.display.Stage;
import flash.display.Graphics;
import flash.events.*;
import flash.utils.Timer;
public class TVWall extends Sprite
{
private var container:Sprite;
private var loadArray:Array=new Array();
private var loadTotalNum:Number = 50;
private var loadURL:String = "image/";
private var imageTotalNum:Number = 4;
private var widthNum:Number = 5;
private var heightNum:Number = 5;
private var myTimer:Timer;
private var count:Number = 0;
private var imageArray:Array = new Array();
private var colorArray:Array = new Array(0xFFCC00,0x006633,0xFF0000,0xFFCC00,0xCC0033,0x77818C,0x0000FF,0x999966,0x000000);
public function TVWall()
{
init();
}
private function init():void{
attachImage();
}
private function getRanNum(type:String):Number{
var total:Number = 1000;
var num:Number;
var dir:Number = Math.floor(Math.random()*2);
var temp:Number;
if (type == "y")
{
num = 600;
}
else
{
num = 800;
}
if (dir == 0)
{
temp = Math.floor(Math.random()*total);
}
else
{
temp = Math.floor(-Math.random()*total);
}
if (temp>0 && temp<num)
{
return -1;
}else{
return temp;
}
}
private function attachImage():void{
container = new Sprite();
addChild(container);
for(var i:Number = 0;i<loadTotalNum;i++){
var ranNum:Number = Math.floor(Math.random()*imageTotalNum)+1;
/*var myURLRequest:URLRequest = new URLRequest(loadURL+ranNum+".jpg");
loadArray[i] = new Loader();
loadArray[i].load(myURLRequest);
*/
var sprite:Sprite = new Sprite();
var ranNum:Number = Math.floor(Math.random()*9);
var colNum:Number = colorArray[ranNum];
sprite.graphics.beginFill(colNum);
var xpos:Number = i*50;
var ypos:Number = 0;
var random_x:Number = getRanNum("x");
var random_y:Number = getRanNum("y");
while(random_x==-1){
random_x=getRanNum("x");
}
while(random_y==-1){
random_y=getRanNum("y");
}
sprite.graphics.drawRect(0,0,50,50);
loadArray[i] = sprite;
//loadArray[i].x = random_x;
//loadArray[i].y = random_y;
//configureListeners(loadArray[i].contentLoaderInfo);
container.addChildAt(loadArray[i],i);
}
startImageMove();
}
private function startImageMove():void{
myTimer = new Timer(300,100);
myTimer.addEventListener(TimerEvent.TIMER,timerHandler);
myTimer.start();
}
public function timerHandler(e:TimerEvent):void{
if(count<loadTotalNum){
imageArray[count] = new ImageControl(container,loadArray[count],count);
count++;
}else{
myTimer.stop();
}
}
}
}
//ImageControl.as
package
{
import flash.display.Sprite;
import flash.events.*;
import flash.display.Loader;
import flash.utils.Timer;
public class ImageControl extends Sprite
{
//private var root;
private var indexNum:Number;
private var myLoader:Sprite;
public var container:Sprite;
public var myTimer:Timer;
private var count:Number;
private var speed:Number = 2;
private var intervalTime:Number;
private var row:Number;
private var col:Number;
private var widthNum:Number = 10;
private var heightNum:Number = 5;
public function ImageControl(c:Sprite,l:Sprite,i:Number){
//this.root = r;
this.container = c;
this.indexNum = i;
this.myLoader = l;
col = Math.floor(indexNum / widthNum);
row = indexNum % widthNum;
//trace("indexNum="+indexNum);
//trace("col="+col);
//trace("row="+row);
//this.addEventListener(Event.ENTER_FRAME,enterFrame);
myLoader.addEventListener(MouseEvent.MOUSE_OVER,mouseOverHandle);
myLoader.addEventListener(MouseEvent.MOUSE_OUT,mouseOutHandle);
myTimer = new Timer(100,100);
myTimer.addEventListener(TimerEvent.TIMER,enterFrame);
myTimer.start();
}
public function mouseOverHandle(e:MouseEvent):void{
container.setChildIndex(myLoader, container.numChildren-1);
myLoader.width =100;
myLoader.height =100;
}
public function mouseOutHandle(e:MouseEvent):void{
container.setChildIndex(myLoader, indexNum);
myLoader.width =50;
myLoader.height =50;
}
public function enterFrame(e:Event):void{
speed -= 0.025;
if (speed < 1)
{
myTimer.stop();
}
else
{
var end_x:Number= row*50;
var end_y:Number = col*50;
myLoader.x += (end_x - myLoader.x) * speed;
myLoader.y += (end_y - myLoader.y) * speed;
if (Math.abs(end_x - myLoader.x) < 0.001)
{
trace("~~~~~~~~~~~~~~~~~~~~~~~~~");
myLoader.x = end_x;
myLoader.y = end_y;
myTimer.stop();
//delete myLoader.onEnterFrame;
}
}
}
}
}
Flash 动画
:
0
评论
Comments
日志分类
首页
[116]
Flash&AS2
[56]
FMS
[3]
Flex&AS3
[5]
Asp
[5]
My Works
[13]
My Life
[34]