Copy link to clipboard
Copied
...so that I can add the next image. and use a tween alpha to show it. If you test this, (just rename any images by the image names I use and export to as3 from library). You can see that the perlinnoise is continually existing in the background. For simplicity and testing, I'm tweening only two halves of an image as I'm testing, but actually I would like to eventually tween many parts (copyPixels) of the original image.
I'm trying to get this to work because Tween doesn't work when you're trying to tween only one index of an array (so I can time each index differently), even if I name each index item in the array.
Interestingly enough when I use the loop and set the x property of the new Rectangle to ix the bit of code below works to stop the perlin noise. But as soon as I remove the loop, the flag.fillRect(flag.rect, 0); doesn't work.
if (newMC2.alpha == 1) {
found = true;//stage.removeChildAt(0);stage.removeChild(flag);ary.splice(0);
break loop;
//break scloop;
//break noise;
flag.fillRect(flag.rect, 0);
}//END if
import flash.display.*;
import flash.events.Event;
import flash.events.TimerEvent;
import flash.geom.Rectangle;
import flash.geom.Point;
import flash.utils.Timer;
import flash.utils.setTimeout;
import fl.transitions.Tween;
import fl.transitions.TweenEvent;
import fl.transitions.easing.*;
var ary:Array = [0,14,28,42,56,70,84,98,112,126,140,154,168,182,196,210,224,238,252,266,280,294,308,322,336,350,364,378,392,406,420,434,448,462,476,490,504,518,532,546,560,574,588,602,604];
var pW:uint = 301;
var xyPnt:Point = new Point(0,0);
var rippleSz:uint = 160;
var scalex:Number = 50;
var scaley:Number = 100;
var channels:uint = BitmapDataChannel.BLUE;
var chX:uint = channels; var chY:uint = channels;
var oct:uint = 1;
var dmode:String = DisplacementMapFilterMode.COLOR;
var color:uint = 0xFFFFFFFF;
var dalpha:Number = 1;
var fW:uint = 603; var fH:uint = 214;
var fData:BitmapData = new BitmapData(fW,fH);//perlinnoise applied to this
var flagBmp:Bitmap = new Bitmap(fData);
var timer:Timer = new Timer(10000,4);
timer.addEventListener(TimerEvent.TIMER, vPic);
timer.start();
addChild(flagBmp);//adds the container bitmap object to the stage
var lwyData0:BitmapData = new lawyers_sprite;
var lkeData1:BitmapData = new lake_sprite;
var dckData2:BitmapData = new duck_sprite;
var ctyData3:BitmapData = new cotie_sprite;
var fRect:Rectangle = new Rectangle(0,0,fW,fH);
var tempFDataX:BitmapData = new BitmapData(fW,fH);
var img1:BitmapData = lwyData0;
var nPic:BitmapData = lkeData1;
tempFDataX.copyPixels(img1,fRect,new Point());
var matrix:Matrix = new Matrix();
var fData2:BitmapData=new BitmapData(fW,fH,false);
fData2.draw(tempFDataX,matrix,null,null,fRect,true);
var flag:Bitmap = new Bitmap(fData2);
addChild(flag);
function vPic(event:Event):void {
var ct:uint = timer.currentCount;
switch (ct){
case 0:break;
case 1:
img1 = lwyData0;
nPic = lkeData1; break;
case 2:
img1 = lkeData1;
nPic = dckData2; break;
case 3:
img1 = dckData2;
nPic = ctyData3; break;
case 4:
img1 = ctyData3;
nPic = lwyData0; timer.reset(); timer.start(); break;
default:
img1 = lwyData0;
nPic = lkeData1; break;
}
tempFDataX.copyPixels(img1,fRect,new Point());
var matrix:Matrix = new Matrix();
var fData2:BitmapData=new BitmapData(fW,fH);
fData2.draw(tempFDataX,matrix,null,null,fRect,true);
var flag:Bitmap = new Bitmap(fData2);
addChild(flag);
var found:Boolean = new Boolean();
flagBmp.blendMode = BlendMode.HARDLIGHT;
flagBmp.alpha = .3;
stage.addEventListener(Event.ENTER_FRAME, wind);
rippleSz = 160;
var rippleSz2:Number = 160;
var offset0:Point = new Point(0,0);
scalex = 50;
scaley = 100;
function wind(event:Event):void {
offset0.y-=.5;
offset0.x-=5;
rippleSz2-=1;
noise: if (rippleSz2>100) {
fData.perlinNoise(rippleSz2,rippleSz,oct,1,true,true,5,false,[offset0]);
var replaceData:DisplacementMapFilter=new DisplacementMapFilter(fData,xyPnt,chX,chY,scalex,scaley,dmode,color,dalpha);
var replaceDataAry:Array=new Array(replaceData);
flag.filters=replaceDataAry;
flag.smoothing=true;
break noise;
}
else {
scloop: if ((scalex<=50) && (scaley<=100) && (found==false)){
if ((scalex>=0) && (scaley>=0)){
offset0.y-=.5;
offset0.x-=5;
rippleSz2+=.5;
scalex-=1;
scaley-=2;
fData.perlinNoise(rippleSz2,rippleSz,oct,1,true,true,5,false,[offset0]);
var replaceData2:DisplacementMapFilter=new DisplacementMapFilter(fData,xyPnt,chX,chY,scalex,scaley,dmode,color,dalpha);
var replaceDataAry2:Array=new Array(replaceData2);
flag.filters=replaceDataAry2;
flag.smoothing=true;
//flag.fillRect(flag.rect, 0);
break scloop;
}
else {
//trace(ct);
var StageObj:Stage = stage;
//loop: for each (var ix:uint in ary) {
var newBmd:BitmapData = new BitmapData(pW,fH);
newBmd.copyPixels(nPic,new Rectangle(0,0,pW,fH),xyPnt,null,null,false);
var pix:Bitmap = new Bitmap(newBmd);
pix.x = 0;
//pix.alpha = .1;
var newMC:MovieClip = new MovieClip();
stage.addChild(newMC);
newMC.x = 0;
newMC.alpha = .1;
newMC.addChild(pix);
var newBmd2:BitmapData = new BitmapData(pW,fH);
newBmd2.copyPixels(nPic,new Rectangle(302,0,pW,fH),xyPnt,null,null,false);
var pix2:Bitmap = new Bitmap(newBmd2);
pix2.x = 0;
//pix.alpha = .1;
var newMC2:MovieClip = new MovieClip();
stage.addChild(newMC2);
newMC2.x = 301;
newMC2.alpha = .1;
newMC2.addChild(pix2);
//var twTimer:Timer = new Timer (2000,44); //ary.length is 45
//twTimer.addEventListener(TimerEvent.TIMER, doTween);
//twTimer.start();
var twn:Tween = new Tween(newMC,"alpha",Strong.easeIn,.1,1,1.5,true);
twn.stop();
setTimeout(twn.start,1000);
var twn2:Tween = new Tween(newMC,"alpha",Strong.easeIn,.1,1,1.5,true);
twn2.stop();
setTimeout(twn2.start,3000);
/*if (newMC2.alpha == 1) {
found = true;//stage.removeChildAt(0);stage.removeChild(flag);ary.splice(0);
break loop;
//break scloop;
//break noise;
flag.fillRect(flag.rect, 0);
}//END if
}//END loop*/
//tween = new Tween(newMC, "y", Strong.easeOut, -214, 0, 1.5, true);
}//END else
}//END if
} //END else
} //END wind
}//END vPic
OR does any one know the math to move each pixel, so that the whole image waves like a flag, without perllinnoise, so that I can start and stop the waving when desired.
assign flag.filters to an zero-length array.
Copy link to clipboard
Copied
assign flag.filters to an zero-length array.
Copy link to clipboard
Copied
Thank you soo much, kglad!! It worked!! Yiiiippppeee! ....and I also forgot to add the found = true; at the end of the innemost nested else, and that fixed the perlinnoise from progressively changing as it looped through the main timer and entered the wind function.
Copy link to clipboard
Copied
For anyone reading this, below is how I did what kglad told me to do. Below is an excerpt of the innermost nested else statement. Note that I also removed "var StageObj:Stage = stage;" and changed "stage.addChild(newMC);" to "addChild(newMC);"
else {
//trace(ct);
flag.filters = [];
//loop: for each (var ix:uint in ary) {
var newBmd:BitmapData = new BitmapData(pW,fH);
newBmd.copyPixels(nPic,new Rectangle(0,0,pW,fH),xyPnt,null,null,false);
var pix:Bitmap = new Bitmap(newBmd);
pix.x = 0;
//pix.alpha = .1;
var newMC:MovieClip = new MovieClip();
addChild(newMC);
newMC.x = 0;
newMC.alpha = .2;
newMC.addChild(pix);
Copy link to clipboard
Copied
you're welcome.
you can also use:
replaceDataAry2.length=0;
flag.filters=replaceDataAry2;
which is a nifty way of clearing the storage space occupied by an array (replaceDataAry2) with creating a new array because it's more efficient than:
replaceDataAr2=[];
and could be import when coding for mobiles and resetting lots of arrays or repeatedly resetting the same array.
Find more inspiration, events, and resources on the new Adobe Community
Explore Now