works fine after correcting some commentlines, seems copy-paste went wrong somehow cheers
--- In [email protected], "helihobby" <[EMAIL PROTECTED]> wrote: > > No that's a different lib ... > can anyone get this one working ..... please ... > > --- In [email protected], "Corey Smaller" <corey_smaller@> > wrote: > > > > - > > http://flexlib.googlecode.com/svn/trunk/docs/flexlib/controls/Fire.html > > > > is this the same code? should work > > > > > > > > -- In [email protected], "helihobby" <helihobby@> wrote: > > > > > > I got this Effect from a friend and its written in Flash but all in > > > Actionscript 3 so it should work for Flex as well ... right ? > > > > > > The code is posted... > > > > > > Can anyone help get this to work. > > > Its an amazing fire effect. > > > > > > Here is the code. ( PS in Flash CS3 it works great !!! ) > > > > > > > > > > > > > > > <?xml version="1.0" encoding="utf-8"?> > > > <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" > > > layout="absolute" creationComplete="init()"> > > > > > > > > > <mx:Script> > > > <![CDATA[ > > > > > > > > > import flash.display.BitmapData; > > > import flash.geom.Rectangle; > > > import flash.geom.Point; > > > import flash.geom.Matrix; > > > import flash.filters.ColorMatrixFilter; > > > import flash.filters.GlowFilter; > > > import flash.filters.DisplacementMapFilter; > > > > > > private function setFire(mc:MovieClip):MovieClip { > > > // hide the original MC > > > mc.visible =false; > > > // calculate the bounds and apply aa padding offset to > > > accomodate > > > the FX > > > var bounds:Object = mc.getBounds(mc); > > > var offset_y:Number =30 > > > var offset_x:Number =10 > > > var w:Number = bounds.width +offset_x > > > var h:Number = bounds.height +offset_y > > > bounds.x=bounds.x-offset_x/2 > > > bounds.y=bounds.y-offset_y/2 > > > // creat our FX copy > > > var clip=new MovieClip(); > > > //create a 'holder' so we can math the original clips registration > > > point exactly > > > var holder:MovieClip=new MovieClip() > > > //add 'clip' to the main display object and add > > > 'holder' as a child > > > of 'clip'. > > > this.addChild(clip); > > > clip.addChild(holder); > > > holder.name="fire_holder"+clip.getChildIndex(holder); > > > // set up our bitmap data > > > var fireMC:Bitmap=new Bitmap(); > > > var shad:Bitmap=new Bitmap() > > > var grad:Sprite=new Sprite();; > > > // set up the flame colouring > > > var fillType:String = GradientType.LINEAR; > > > var colors:Array > > > var glow:GlowFilter > > > // try some different colour flames out here: > > > colors = [0xFF0000, 0xFF6600, 0xFFCC00, 0xFFFFFF] > > > //colors = [0x33FFFF, 0x3399FF, 0x33FFFF, 0xFFFFFF] > > > //colors = [0x006600, 0x009900, 0x00CC00, 0xFFFFFF] > > > //colors = [0xCC0099, 0xFF66FF, 0xFFCCFF, 0xFFFFFF] > > > //colors = [0x9900FF, 0xCC99FF,0xCCCCFF, 0xFFFFFF] > > > var alphas:Array = [100, 100, 100, 100]; > > > var ratios:Array = [90, 110,130, 255]; > > > var interpolationMethod:String= > > > InterpolationMethod.LINEAR_RGB > > > var matr:Matrix = new Matrix(); > > > matr.createGradientBox( w, h, -(270/180)*Math.PI,0, h); > > > var spreadMethod:String = SpreadMethod.REFLECT; > > > // draw the flame colouring > > > grad.graphics.beginGradientFill(fillType, colors, > > > alphas, ratios, > > > matr, spreadMethod, interpolationMethod); > > > grad.graphics.moveTo(0, 0); > > > grad.graphics.lineTo(w, 0); > > > grad.graphics.lineTo(w, h); > > > grad.graphics.lineTo(0, h); > > > grad.graphics.lineTo(0, 0); > > > grad.graphics.endFill(); > > > //holder.addChild(grad);//uncomment this to see that > > > your gradient > > > is working properly > > > // create a glow filter > > > glow = new GlowFilter(colors[1], 1, 13, 13, 2, 1, > > > false, false); > > > // set up our bitmap data > > > var gradBmp:BitmapData = new BitmapData(w, h, true, > > > 0x00000000); > > > gradBmp.draw(grad); > > > var bitmap:BitmapData = new BitmapData(w, h, true, > > > 0x00000000); > > > var fireBitmap:BitmapData = new BitmapData(w, h, true, 0x00000000); > > > // copy the original MC > > > bitmap.draw(mc, new > > > Matrix(1,0,0,1,bounds.x*-1,bounds.y*-1)); > > > // set x and y positions > > > holder.x=bounds.x > > > holder.y=bounds.y > > > clip.x=mc.x; > > > clip.y=mc.y; > > > // combine the gradient colours with the non alpha'd > > > area of the MC > > > bitmap.copyPixels(gradBmp, gradBmp.rect, new > > > Point(0,0), bitmap, > > > new Point(0, 0), true); > > > // create a silhouette to sit on top > > > var shadowMap:BitmapData = bitmap.clone(); > > > // add the fire mc to the display object > > > fireMC.bitmapData=fireBitmap > > > holder.addChild(fireMC) > > > var matrix:Array = new Array(); > > > matrix = matrix.concat([-1, 0, 0, 0, 0]); > > > matrix = matrix.concat([0, -1, 0, 0, 0]); > > > matrix = matrix.concat([0, 0, -1, 0, 0]); > > > matrix = matrix.concat([0, 0, 0, 1, 0]); > > > var darken = new ColorMatrixFilter(matrix); > > > var offset = new Point(0, 0); > > > var yOff = 4; > > > // create our displacement map bitmap data > > > var disp:BitmapData = new BitmapData(w, h); > > > // create our offsets > > > var offsets = new Array(); > > > // create a blur filter > > > var blur1 = new flash.filters.BlurFilter(3,20, 1); > > > offsets.push(new flash.geom.Point()); > > > //create a random seed > > > var seed= Math.round(Math.random()*300); > > > var p = new Point() > > > // apply static FX to the shadow map > > > shadowMap.applyFilter(shadowMap,shadowMap.rect,p,darken) > > > shadowMap.applyFilter(shadowMap,shadowMap.rect,p,glow) > > > // redraw loop > > > var redraw = function():void { > > > //increment offset > > > offsets[0].y += yOff; > > > // create perlin noise for displacement filter > > > disp.perlinNoise(20, 30, 1, seed, true, true, > > > 1, false, offsets); > > > // create displacement filter > > > var displaceFilter:DisplacementMapFilter = new > > > DisplacementMapFilter(disp, offset, 1, 1, 50, 50, 'color'); > > > // apply filters to bitmap datat > > > fireBitmap.applyFilter(bitmap, bitmap.rect, > > > p,blur1) > > > fireBitmap.applyFilter(fireBitmap, bitmap.rect,p,displaceFilter) > > > //copy the shadow map > > > var fireshadowMap=fireBitmap.clone(); > > > // combine the bitmap data > > > fireBitmap.copyPixels(shadowMap, > > > shadowMap.rect, p, shadowMap,p, > > > true); > > > fireBitmap.copyPixels(fireshadowMap, > > > shadowMap.rect, p, > > > fireshadowMap,p, true); > > > > > > }; > > > // add loop > > > clip.addEventListener("enterFrame",redraw); > > > // swap depths with original mc (comment out > > > mc.visible=false > to use) > > > this.swapChildren(clip, mc) > > > //create kill datat > > > clip.bitmap1=bitmap > > > clip.bitmap2=gradBmp > > > clip.bitmap3=shadowMap > > > clip.bitmap4=disp > > > clip.listener=redraw > > > clip.original=mc; > > > // return a reference to the new FX MC > > > return clip; > > > } > > > > > > private function removeFX(clip:MovieClip):void { > > > clip.removeEventListener("enterFrame", clip.listener); > > > clip.original.visible=true; > > > clip.bitmap1.dispose(); > > > clip.bitmap2.dispose(); > > > clip.bitmap3.dispose(); > > > clip.bitmap4.dispose(); > > > this.removeChild(clip); > > > } > > > > > > private function init():void > > > { > > > // to call the fx > > > //fxClip:MovieClip=setFire(mc:MovieClip):MovieClip; > > > var flamingText = setFire(bb as MovieClip)// > > > // to get rid of the FX: > > > //removeFX(flamingText) > > > } > > > > > > > > > > > > ]]> > > > </mx:Script> > > > <mx:Button x="140" y="118" label="Button" id="bb" > > > click="{setFire(this as MovieClip)}"/> > > > > > > > > > </mx:Application> > > > > > >

