in4core
27.02.2012, 20:36
Собственно не смотрел как организован тот же tweenMax , но думаю здесь мне дадут более понятный ответ.
Задача : статический класс принимающий некий ( или несколько ) объектов - работает с ними раздельно.
Тоесть в твинмаксе я могу TweenMax.to(object1) , TweenMax.to(object2) и т.п.
Вот набросок быдло-кода, собственно вот и хочу узнать как модифицировать, чтобы работать с каждым объектом отдельно, а не было перекрытия методов
package com.in4core.text.effects
{
import com.greensock.TweenMax;
import flash.display.Bitmap;
import flash.display.BitmapData;
import flash.display.DisplayObject;
import flash.display.DisplayObjectContainer;
import flash.display.Sprite;
import flash.events.TimerEvent;
import flash.geom.Matrix;
import flash.geom.Point;
import flash.geom.Rectangle;
import flash.utils.describeType;
import flash.utils.Dictionary;
import flash.utils.Timer;
/**
* ...
* @author in4core lab
*/
public final class GhostLibrary
{
private static var _objectArray:Dictionary = new Dictionary(true);
private static var _iterator:int = 0;
private static var _tempSource:DisplayObject;
private static var _tempArray:Array = [];
public static function cubicBlurTransition(source:DisplayObject , holder:DisplayObjectContainer,
numW:int , numH:int , oneTime:int = 20 , isStart:Boolean = false):void {
const timer:Timer = new Timer(oneTime);
const sprite:Sprite = new Sprite();
timer.addEventListener(TimerEvent.TIMER , update_cubicBlurTransition);
_objectArray[ source ] = [ holder , timer , sprite ];
_tempSource = source;
const w:int = source.width / numW;
const h:int = source.height / numH;
const b:BitmapData = new BitmapData(source.width , source.height, true, 0);
b.draw(source);
for (var i:int = 0; i < numW + 1; i ++) {
for (var j:int = 0; j < numH + 1; j++) {
const bd:BitmapData = new BitmapData(w + 1, h + 1, false);
bd.copyPixels(b , new Rectangle(i * w , j * h , w , h ) , new Point() );
const bt:Bitmap = new Bitmap(bd , 'never' , true);
sprite.addChild(bt);
_tempArray.push(bt);
bt.alpha = 0;
bt.x = i * w;
bt.y = j * h;
}
}
holder.addChild(sprite);
if (isStart) source.visible = false , timer.start();
}
private static function update_cubicBlurTransition(e:TimerEvent):void {
var tar:Timer = e.target as Timer;
var num:int = Math.floor( Math.random() * _tempArray.length );
if (!_tempArray.length) {
tar.stop();
return;
}
var c:Bitmap = _tempArray[num];
if (_tempArray.length > 1 ) TweenMax.fromTo ( c , 1 , { blurFilter: { blurX:80 } }, { blurFilter: { blurX:0 } , alpha:1 } );
else TweenMax.fromTo ( c , 1 , { blurFilter: { blurX:80 } }, { blurFilter: { blurX:0 } , alpha:1 ,
onComplete:onComplete_cubicBlurTransition } );
_tempArray.splice(num,1);
}
private static function onComplete_cubicBlurTransition():void {
_objectArray[_tempSource][0].removeChild(_objectArray[_tempSource][2]);
_tempSource.visible = true;
}
}
}
Задача : статический класс принимающий некий ( или несколько ) объектов - работает с ними раздельно.
Тоесть в твинмаксе я могу TweenMax.to(object1) , TweenMax.to(object2) и т.п.
Вот набросок быдло-кода, собственно вот и хочу узнать как модифицировать, чтобы работать с каждым объектом отдельно, а не было перекрытия методов
package com.in4core.text.effects
{
import com.greensock.TweenMax;
import flash.display.Bitmap;
import flash.display.BitmapData;
import flash.display.DisplayObject;
import flash.display.DisplayObjectContainer;
import flash.display.Sprite;
import flash.events.TimerEvent;
import flash.geom.Matrix;
import flash.geom.Point;
import flash.geom.Rectangle;
import flash.utils.describeType;
import flash.utils.Dictionary;
import flash.utils.Timer;
/**
* ...
* @author in4core lab
*/
public final class GhostLibrary
{
private static var _objectArray:Dictionary = new Dictionary(true);
private static var _iterator:int = 0;
private static var _tempSource:DisplayObject;
private static var _tempArray:Array = [];
public static function cubicBlurTransition(source:DisplayObject , holder:DisplayObjectContainer,
numW:int , numH:int , oneTime:int = 20 , isStart:Boolean = false):void {
const timer:Timer = new Timer(oneTime);
const sprite:Sprite = new Sprite();
timer.addEventListener(TimerEvent.TIMER , update_cubicBlurTransition);
_objectArray[ source ] = [ holder , timer , sprite ];
_tempSource = source;
const w:int = source.width / numW;
const h:int = source.height / numH;
const b:BitmapData = new BitmapData(source.width , source.height, true, 0);
b.draw(source);
for (var i:int = 0; i < numW + 1; i ++) {
for (var j:int = 0; j < numH + 1; j++) {
const bd:BitmapData = new BitmapData(w + 1, h + 1, false);
bd.copyPixels(b , new Rectangle(i * w , j * h , w , h ) , new Point() );
const bt:Bitmap = new Bitmap(bd , 'never' , true);
sprite.addChild(bt);
_tempArray.push(bt);
bt.alpha = 0;
bt.x = i * w;
bt.y = j * h;
}
}
holder.addChild(sprite);
if (isStart) source.visible = false , timer.start();
}
private static function update_cubicBlurTransition(e:TimerEvent):void {
var tar:Timer = e.target as Timer;
var num:int = Math.floor( Math.random() * _tempArray.length );
if (!_tempArray.length) {
tar.stop();
return;
}
var c:Bitmap = _tempArray[num];
if (_tempArray.length > 1 ) TweenMax.fromTo ( c , 1 , { blurFilter: { blurX:80 } }, { blurFilter: { blurX:0 } , alpha:1 } );
else TweenMax.fromTo ( c , 1 , { blurFilter: { blurX:80 } }, { blurFilter: { blurX:0 } , alpha:1 ,
onComplete:onComplete_cubicBlurTransition } );
_tempArray.splice(num,1);
}
private static function onComplete_cubicBlurTransition():void {
_objectArray[_tempSource][0].removeChild(_objectArray[_tempSource][2]);
_tempSource.visible = true;
}
}
}