flash 墙
部分源代码 MainMovie.as
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
package com.view.swf
{
import com.global.config;
import com.loader.imageLoader;
import flash.display.*;
import flash.events.*;
import flash.geom.Point;
import flash.geom.Rectangle;
import flash.utils.Timer;
import com.loader.imageLoading;
public class MainMovie extends Sprite
{
private var stageW :Number
private var stageH :Number
private var blockesW :Number;
private var blockesH :Number;
private var sprite2D :Sprite;
private var bitmapArr :Array;
private var jx_h :Number;
private var tempStr :String;
private var tempBox :*;
private var controlArr :Array;
private var allSpriteArr :Array;
private var controlArr_ :Array;
private var imageloading :imageLoading;
private var timer :Timer;
private var num :Number;
private var num_ :Number;
private var indexArr :Array;
private var lock :Boolean;
public function MainMovie()
{
init();
}
private function init()
{
num = 0;
num_ = 0;
lock = false;
jx_h = config.jx_h;
stageW = 720;
stageH = 289;
blockesW = 60;
blockesH = 60;
sprite2D = new Sprite();
bitmapArr = new Array();
controlArr = new Array();
controlArr_ = new Array();
allSpriteArr = new Array();
indexArr = new Array();
indexArr=[9,8,7,6,5,4,3,2,1,0,10,11,12,13,14,15,16,17,18,19,29,28,27,26,25,24,23,22,21,20,30,31,32,33,34,35,36,37,38,39]
tempStr = "";
this.addChildAt(sprite2D, this.numChildren);
//加载背景图片
loadImage();
//timer
timer = new Timer(150);
timer.addEventListener(TimerEvent.TIMER, timerEvent);
timer.start();
}
private function loadImage()
{
var url=config.path+"image/bg.jpg"
imageloading = new imageLoading(url);
imageloading.addEventListener("complete",getBitmap);
}
private function getBitmap(event:Event)
{
//拆分背景图片
cutImage(imageloading.getLoaderContent);
}
private function cutImage(bitmapData:BitmapData)
{
imageloading = null;
var bitmapArrX:Array = new Array();
var bitmapArrY:Array = new Array();
var maxI:Number = int(bitmapData.width / blockesW)
var maxJ:Number = int(bitmapData.height / blockesH)
if (bitmapData.width % blockesW != 0)
{
maxI++;
}
if (bitmapData.height % blockesH != 0)
{
maxJ++;
}
for (var j:Number = 0; j <= maxJ; j++ )
{
for (var i:Number = 0; i < maxI; i++ )
{
var rect:Rectangle = new Rectangle(i*blockesW, j*blockesH, blockesW, blockesH);
var pt :Point = new Point(0, 0);
var newBitmapData:BitmapData = new BitmapData(blockesW, blockesH)
newBitmapData.copyPixels(bitmapData, rect, pt);
var newBitmap:Bitmap = new Bitmap(newBitmapData, "auto", true)
bitmapArrX.push(i * blockesW);
bitmapArrY.push(j * blockesH);
bitmapArr.push(newBitmap);
}
}
//组合背景图片
combinationImage(maxI,maxJ,bitmapArrX,bitmapArrY);
}
private function combinationImage(maxI:Number, maxJ:Number, arrX:Array, arrY:Array)
{
var max:Number = maxI * maxJ;
for (var i:Number = 0; i < max; i++)
{
var sprite:LR_roataion = new LR_roataion();
sprite.img.addChild(bitmapArr[i])
addLogo(sprite.logo)
sprite2D.addChildAt(sprite,i);
sprite.x = (i % maxI) * blockesW+30; //arrX[i]
sprite.y = int(i / maxI) * blockesH+30 + jx_h; //arrY[i]
sprite.name = i + "";
if (i % maxI != 0 && i % maxI != 11 && int(i / maxI)!=4)
{
sprite.addEventListener(MouseEvent.MOUSE_OVER, spriteMouseOver)
sprite.addEventListener(MouseEvent.MOUSE_OUT, spriteMouseOut)
allSpriteArr.push(sprite)
}else {
sprite.addEventListener(MouseEvent.MOUSE_OUT, spriteMouseOut_)
}
}
}
private function spriteMouseOver(event:MouseEvent)
{
var sprite = event.currentTarget ;
tempBox = sprite;
if (sprite.currentFrame == 1)
{
sprite.gotoAndPlay("start");
}
}
private function spriteMouseOut(event:MouseEvent)
{
var sprite = event.currentTarget;
controlArr.push(sprite);
}
private function spriteMouseOut_(event:MouseEvent)
{
if (tempBox != null)
{
tempBox.gotoAndPlay("finish");
tempBox = null;
lock = true
for (var i:Number = 0; i < controlArr.length; i++ )
{
if (tempBox == controlArr[i])
{
controlArr.splice(i, 1);
}
}
}
}
private function timerEvent(event:TimerEvent)
{
//trace(controlArr[controlArr.length-1].name)
if (controlArr.length == 0 && tempBox == null && allSpriteArr.length!=0)
{
if (num==-1)
{
num = 1;
lock = false
}
if (num < 20)
{
num++;
num_ = 0;
}else {
if (num_ < indexArr.length)
{
num_++;
var _num_:Number = Number(indexArr[num_ -1]);
if (allSpriteArr[_num_] != null)
{
allSpriteArr[_num_].gotoAndPlay(2);
controlArr_.push(allSpriteArr[_num_]);
}
}
}
}else {
for (var i:Number = 0; i < controlArr.length; i++ )
{
if (controlArr[i].currentFrame == 18 && controlArr[i]!=tempBox)
{
controlArr[i].gotoAndPlay("finish");
controlArr.splice(i, 1);
}
}
if (tempBox != null)
{
if (tempBox.currentFrame == 1)
{
tempBox.gotoAndPlay(2);
}
}
}
for (var j:Number = 0; j < controlArr_.length; j++ )
{
if (controlArr_[j].currentFrame == 18 && controlArr_[j]!=tempBox)
{
if (controlArr_[j] != null)
{
controlArr_[j].gotoAndPlay("finish");
}
controlArr_.splice(j, 1);
}
}
if (controlArr_.length==0 && j != 0)
{
num=-1
}
}
private function addLogo(sprite:*)
{
var url:String = config.path + "image/" + (Math.round(Math.random()*113)+1) + ".jpg"
var imageLoader_ = new imageLoader(url, sprite);
}
private function closeAll()
{
timer.removeEventListener(TimerEvent.TIMER, timerEvent);
timer.stop();
}
}
}
{
import com.global.config;
import com.loader.imageLoader;
import flash.display.*;
import flash.events.*;
import flash.geom.Point;
import flash.geom.Rectangle;
import flash.utils.Timer;
import com.loader.imageLoading;
public class MainMovie extends Sprite
{
private var stageW :Number
private var stageH :Number
private var blockesW :Number;
private var blockesH :Number;
private var sprite2D :Sprite;
private var bitmapArr :Array;
private var jx_h :Number;
private var tempStr :String;
private var tempBox :*;
private var controlArr :Array;
private var allSpriteArr :Array;
private var controlArr_ :Array;
private var imageloading :imageLoading;
private var timer :Timer;
private var num :Number;
private var num_ :Number;
private var indexArr :Array;
private var lock :Boolean;
public function MainMovie()
{
init();
}
private function init()
{
num = 0;
num_ = 0;
lock = false;
jx_h = config.jx_h;
stageW = 720;
stageH = 289;
blockesW = 60;
blockesH = 60;
sprite2D = new Sprite();
bitmapArr = new Array();
controlArr = new Array();
controlArr_ = new Array();
allSpriteArr = new Array();
indexArr = new Array();
indexArr=[9,8,7,6,5,4,3,2,1,0,10,11,12,13,14,15,16,17,18,19,29,28,27,26,25,24,23,22,21,20,30,31,32,33,34,35,36,37,38,39]
tempStr = "";
this.addChildAt(sprite2D, this.numChildren);
//加载背景图片
loadImage();
//timer
timer = new Timer(150);
timer.addEventListener(TimerEvent.TIMER, timerEvent);
timer.start();
}
private function loadImage()
{
var url=config.path+"image/bg.jpg"
imageloading = new imageLoading(url);
imageloading.addEventListener("complete",getBitmap);
}
private function getBitmap(event:Event)
{
//拆分背景图片
cutImage(imageloading.getLoaderContent);
}
private function cutImage(bitmapData:BitmapData)
{
imageloading = null;
var bitmapArrX:Array = new Array();
var bitmapArrY:Array = new Array();
var maxI:Number = int(bitmapData.width / blockesW)
var maxJ:Number = int(bitmapData.height / blockesH)
if (bitmapData.width % blockesW != 0)
{
maxI++;
}
if (bitmapData.height % blockesH != 0)
{
maxJ++;
}
for (var j:Number = 0; j <= maxJ; j++ )
{
for (var i:Number = 0; i < maxI; i++ )
{
var rect:Rectangle = new Rectangle(i*blockesW, j*blockesH, blockesW, blockesH);
var pt :Point = new Point(0, 0);
var newBitmapData:BitmapData = new BitmapData(blockesW, blockesH)
newBitmapData.copyPixels(bitmapData, rect, pt);
var newBitmap:Bitmap = new Bitmap(newBitmapData, "auto", true)
bitmapArrX.push(i * blockesW);
bitmapArrY.push(j * blockesH);
bitmapArr.push(newBitmap);
}
}
//组合背景图片
combinationImage(maxI,maxJ,bitmapArrX,bitmapArrY);
}
private function combinationImage(maxI:Number, maxJ:Number, arrX:Array, arrY:Array)
{
var max:Number = maxI * maxJ;
for (var i:Number = 0; i < max; i++)
{
var sprite:LR_roataion = new LR_roataion();
sprite.img.addChild(bitmapArr[i])
addLogo(sprite.logo)
sprite2D.addChildAt(sprite,i);
sprite.x = (i % maxI) * blockesW+30; //arrX[i]
sprite.y = int(i / maxI) * blockesH+30 + jx_h; //arrY[i]
sprite.name = i + "";
if (i % maxI != 0 && i % maxI != 11 && int(i / maxI)!=4)
{
sprite.addEventListener(MouseEvent.MOUSE_OVER, spriteMouseOver)
sprite.addEventListener(MouseEvent.MOUSE_OUT, spriteMouseOut)
allSpriteArr.push(sprite)
}else {
sprite.addEventListener(MouseEvent.MOUSE_OUT, spriteMouseOut_)
}
}
}
private function spriteMouseOver(event:MouseEvent)
{
var sprite = event.currentTarget ;
tempBox = sprite;
if (sprite.currentFrame == 1)
{
sprite.gotoAndPlay("start");
}
}
private function spriteMouseOut(event:MouseEvent)
{
var sprite = event.currentTarget;
controlArr.push(sprite);
}
private function spriteMouseOut_(event:MouseEvent)
{
if (tempBox != null)
{
tempBox.gotoAndPlay("finish");
tempBox = null;
lock = true
for (var i:Number = 0; i < controlArr.length; i++ )
{
if (tempBox == controlArr[i])
{
controlArr.splice(i, 1);
}
}
}
}
private function timerEvent(event:TimerEvent)
{
//trace(controlArr[controlArr.length-1].name)
if (controlArr.length == 0 && tempBox == null && allSpriteArr.length!=0)
{
if (num==-1)
{
num = 1;
lock = false
}
if (num < 20)
{
num++;
num_ = 0;
}else {
if (num_ < indexArr.length)
{
num_++;
var _num_:Number = Number(indexArr[num_ -1]);
if (allSpriteArr[_num_] != null)
{
allSpriteArr[_num_].gotoAndPlay(2);
controlArr_.push(allSpriteArr[_num_]);
}
}
}
}else {
for (var i:Number = 0; i < controlArr.length; i++ )
{
if (controlArr[i].currentFrame == 18 && controlArr[i]!=tempBox)
{
controlArr[i].gotoAndPlay("finish");
controlArr.splice(i, 1);
}
}
if (tempBox != null)
{
if (tempBox.currentFrame == 1)
{
tempBox.gotoAndPlay(2);
}
}
}
for (var j:Number = 0; j < controlArr_.length; j++ )
{
if (controlArr_[j].currentFrame == 18 && controlArr_[j]!=tempBox)
{
if (controlArr_[j] != null)
{
controlArr_[j].gotoAndPlay("finish");
}
controlArr_.splice(j, 1);
}
}
if (controlArr_.length==0 && j != 0)
{
num=-1
}
}
private function addLogo(sprite:*)
{
var url:String = config.path + "image/" + (Math.round(Math.random()*113)+1) + ".jpg"
var imageLoader_ = new imageLoader(url, sprite);
}
private function closeAll()
{
timer.removeEventListener(TimerEvent.TIMER, timerEvent);
timer.stop();
}
}
}
posted on 2010-02-26 15:26 elvis.zhang 阅读(319) 评论(0) 编辑 收藏 举报