On Mon, Jan 25, 2010 at 1:12 PM, Nathan Mynarcik <nat...@mynarcik.com>wrote:
> Have you tried tracing to see if that function you added is firing? > Thank you. I added one at the top of that function and it didn't fire. So that tells us the problem must be in calling the function: picLoader.addEventListener(Event.ENTER_FRAME, checkFrame3); The only things I changed here when I copied and pasted this function call were changing from checkFrame to checkFrame3, and editing the variable calling the function; namely picLoader. Therefore I presume it must be the latter that is causing the problem. Why? After all, I but replaced an addEventListener (which I then put in checkFrame3): picLoader.addEventListener(PictureLoader.ALL_PICS_LOADED, createParticles); Please advise. TIA, beno > > -----Original Message----- > From: flashcoders-boun...@chattyfig.figleaf.com > [mailto:flashcoders-boun...@chattyfig.figleaf.com] On Behalf Of beno - > Sent: Monday, January 25, 2010 10:57 AM > To: Flash Coders List > Subject: [Flashcoders] AddEventListener > > Hi; > I have the following line of code in the init: > > picLoader.addEventListener(Event.ENTER_FRAME, checkFrame3); > > and this code further on: > > public function checkFrame3(e:Event):void > { > if (e.target.currentFrame == 10) > { > e.target.removeEventListener(Event.ENTER_FRAME, checkFrame); > picLoader.addEventListener(PictureLoader.ALL_PICS_LOADED, createParticles); > picLoader.loadPics(picURLString); > } > } > > I copied a bunch of code from flashandmath.com. The above is my own > addition. It doesn't do anything. What I'd like it to do is, when the movie > enters frame 10, activate the code I copied from flashandmath. If I pull > out > and replace my above-quoted line of code in the init with the same, > everything works. But I'd like to delay this action for so many frames. > Please advise. All code follows. > TIA, > beno > > > package > { > import flash.text.TextField; > import flash.text.TextFormat; > import flash.text.TextFieldAutoSize; > import flash.utils.getTimer; > import com.dangries.loaders.*; > import com.dangries.bitmapUtilities.PictureAtomizer; > import com.dangries.objects.Particle3D; > import com.dangries.geom3D.*; > import com.dangries.display.*; > import flash.filters.BlurFilter; > import flash.geom.ColorTransform; > import flash.geom.Rectangle; > import flash.geom.Point; > import flash.events.Event; > import flash.events.ProgressEvent; > import flash.events.Event; > import flash.events.MouseEvent; > import flash.display.MovieClip; > import com.greensock.*; > import com.greensock.easing.*; > > public class Main extends MovieClip > { > //Import Library Assests > public var picURLString:Array; > public var picLoader:PictureLoader; > public var pic:Array; > public var atomizer:PictureAtomizer; > public var particles:Array; > public var blur:BlurFilter; > public var darken:ColorTransform; > public var board:RotatingParticleBoard; > public var boardRect:Rectangle; > public var filterPoint:Point; > public var p:Particle3D; > public var param:Number; > public var head:HatAndFace; > public var leftEye:Eyeball; > public var rightEye:Eyeball; > public var leftHand:Hand; > public var rightHand:Hand; > public var myPic:picture; > public var myThumb:CloseThumb; > > public function Main() > { > init(); > > } > > public function init():void > { > hatAndFace(); > eyeball1(); > eyeball2(); > myRightHand(); > myLeftHand(); > thePic(); > theThumb(); > picURLString= ["beno.jpg"]; > picLoader = new PictureLoader(); > > board = new RotatingParticleBoard(420,340,true, 0x00000000, 160); > board.setDepthDarken(-10,-80, 1.5); > board.makeFrame(2,0x444444,1); > board.holder.x = stage.stageWidth/2 - board.width/2; > board.holder.y = stage.stageHeight/2 - board.height/2; > //set the initial rotation: > board.currentQ = new Quaternion(Math.cos(Math.PI/12), > Math.sin(Math.PI/12)/Math.sqrt(2),0,-Math.sin(Math.PI/12)/Math.sqrt(2)); > //set the automatic rotation to use while mouse is not dragging: > board.autoQuaternion = new > Quaternion(Math.cos(Math.PI/300),0,Math.sin(Math.PI/300),0); > > blur = new BlurFilter(3,3); > darken = new ColorTransform(1,1,1,0.8); > boardRect = new Rectangle(0,0,board.width,board.height); > filterPoint = new Point(0,0); > //add following code to see arcball silhouette: > /* > var ballOutline:Shape = new Shape(); > ballOutline.graphics.lineStyle(1,0x888888); > ballOutline.graphics.drawCircle(0,0,board.arcballRad); > ballOutline.x = board.width/2; > ballOutline.y = board.height/2; > board.holder.addChild(ballOutline); > */ > > picLoader.addEventListener(Event.ENTER_FRAME, checkFrame3); > } > > //Place Head and Hat on stage and fade in > public function hatAndFace():void > { > head = new HatAndFace(); > head.x = stage.stageWidth/2; > head.y = stage.stageHeight/4; > head.alpha = 0; > addChild(head); > TweenLite.to(head, 2, {autoAlpha:1}); > } > //Place left eye on stage and fade in > public function eyeball1():void > { > leftEye = new Eyeball(); > leftEye.x = head.x - 30; > leftEye.y = head.y + 15; > leftEye.alpha = 0; > addChild(leftEye); > TweenLite.to(leftEye, 2, {autoAlpha:1}); > } > //Place right eye on stage and fade in > public function eyeball2():void > { > rightEye = new Eyeball(); > rightEye.x = head.x + 30; > rightEye.y = head.y + 15; > rightEye.alpha = 0; > addChild(rightEye); > TweenLite.to(rightEye, 2, {autoAlpha:1}); > } > > //Place right hand on stage and fade in > public function myRightHand():void > { > rightHand = new Hand(); > rightHand.x = head.x + 480; > rightHand.y = head.y + 50; > addChild(rightHand); > rightHand.addEventListener(Event.ENTER_FRAME, checkFrame); > } > //Place left hand on stage and fade in > public function myLeftHand():void > { > leftHand = new Hand(); > leftHand.x = head.x - 30; > leftHand.y = head.y + 50; > addChild(leftHand); > // leftHand.addEventListener(Event.ENTER_FRAME, checkFrame); > // TweenMax.fromTo(leftHand, leftHand.totalFrames - 1, > {frame:leftHand.totalFrames}, {frame:1}); > TweenMax.fromTo(leftHand, leftHand.totalFrames - 1, > {frame:leftHand.totalFrames}, {frame:1}); > } > > public function thePic():void > { > myPic = new picture(); > myPic.x = 300; > myPic.y = 350; > addChild(myPic); > myPic.alpha = 0; > TweenLite.to(myPic, 2, {autoAlpha:1}); > TweenMax.to(myPic, 1, {shortRotation:{rotation:60}, x:480}); > } > > public function theThumb():void > { > myThumb = new CloseThumb(); > myThumb.x = 300; > myThumb.y = 350; > addChild(myThumb); > myThumb.addEventListener(Event.ENTER_FRAME, checkFrame2); > } > > function createParticles(evt:Event):void { > pic = picLoader.picArray; > picLoader.removeEventListener(PictureLoader.ALL_PICS_LOADED, > createParticles); > atomizer = new PictureAtomizer(); > atomizer.sampling = 1; > atomizer.spread = 1.33; > atomizer.sampleFuzzX = 0; > atomizer.sampleFuzzY = 0; > atomizer.originX = Math.floor(pic[0].width/2); > atomizer.originY = Math.floor(pic[0].height/2); > atomizer.addEventListener(PictureAtomizer.PARTICLES_CREATED, go); > atomizer.createParticles(pic[0]); > } > > function go(evt:Event):void { > particles = atomizer.particleArray; > atomizer.setPositionsByPic(0,0,0); > stage.addChild(board.holder); > stage.addEventListener(Event.ENTER_FRAME, onEnter); > } > > function onEnter(evt:Event):void { > //Viewpoint-independent changes to particle positions: > //Here we present an example of each particle oscillating > //in the z direction, with amplitude related to the luminance > //of the particle. > param = > > 0.65*Math.min(1.75,Math.max(0,(1-Math.cos(getTimer()*.0003)-0.25*Math.cos(ge > tTimer()*.0006)))); > for (var i:Number = 0; i<= particles.length - 1; i++) { > p = particles[i]; > p.z = param*(p.lum-128); > } > //apply Filters to effect fade-out of old pixels > board.bitmapData.applyFilter(board.bitmapData, boardRect, filterPoint, > blur); > board.bitmapData.colorTransform(boardRect,darken); > > //draw particles > board.drawParticles(particles); > } > //check the hands and stop when they reach the 40 frame > public function checkFrame(e:Event):void > { > if (e.target.currentFrame == 20) > { > e.target.removeEventListener(Event.ENTER_FRAME, checkFrame); > // leftHand.gotoAndStop(leftHand.totalFrames); > // TweenMax.to(leftHand, leftHand.totalFrames-1, {frame:1, > useFrames:true, ease:Linear.easeNone}); > rightHand.gotoAndStop(rightHand.totalFrames); > TweenMax.to(rightHand, rightHand.totalFrames-1, {frame:1, > useFrames:true, ease:Linear.easeNone}); > } > } > > public function checkFrame2(e:Event):void > { > if (e.target.currentFrame == 10) > { > e.target.removeEventListener(Event.ENTER_FRAME, checkFrame); > myThumb.gotoAndStop(myThumb.totalFrames); > } > } > > public function checkFrame3(e:Event):void > { > if (e.target.currentFrame == 10) > { > e.target.removeEventListener(Event.ENTER_FRAME, checkFrame); > picLoader.addEventListener(PictureLoader.ALL_PICS_LOADED, createParticles); > picLoader.loadPics(picURLString); > } > } > > } > } > _______________________________________________ > Flashcoders mailing list > Flashcoders@chattyfig.figleaf.com > http://chattyfig.figleaf.com/mailman/listinfo/flashcoders > > > _______________________________________________ > Flashcoders mailing list > Flashcoders@chattyfig.figleaf.com > http://chattyfig.figleaf.com/mailman/listinfo/flashcoders > _______________________________________________ Flashcoders mailing list Flashcoders@chattyfig.figleaf.com http://chattyfig.figleaf.com/mailman/listinfo/flashcoders