Skip to main content
Known Participant
December 12, 2011
Question

Ugh, so frustrated...

  • December 12, 2011
  • 5 replies
  • 3791 views

Hi, any help would be appreciated.  I'm trying to define a class that will make some textfields appear as if they're a blinking neonsign with a sound clip playing in tandem.  I got the code from a tutorial and it doesn't spit out any errors, but it doesn't do anything either. Please help, I'm desperate.

package ActionScript

{

import flash.net.URLRequest

import flash.display.*;

import flash.utils.*;

import flash.events.*;

import flash.filters.*;

import flash.media.*;

public class Flicker extends MovieClip

{

  private var timerOne:Timer;

  private var timerTwo:Timer;

  private var maxFlicker:Number = .85;

  private var neonClip:Sound = new Sound();

  private var soundControl:SoundChannel = new SoundChannel();

  private var NeonOff:MovieClip = new Title_Off();

  private var NeonOn:MovieClip = new Title_On();

  private var glow:GlowFilter = new GlowFilter(0xFF00FF, 1, 20, 20, 2, 3, false, false);

  private var blur:BlurFilter = new BlurFilter(5, 5, 2);

  private function timerInit():void

  {

   NeonOn.alpha = 0;

   timerOne = new Timer(2000,0);

   timerOne.addEventListener(TimerEvent.TIMER, timerOn);

   timerOne.start();

  }

 

  private function timerOn(e:TimerEvent):void

  {

   neonClip.load(new URLRequest("\Audio\neonClip.mp3"));

   neonClip.play();

   timerOne.stop()

   timerOne.removeEventListener(TimerEvent.TIMER, timerOn);

   addEventListener(Event.ENTER_FRAME, flickerOn);

  }

 

  private function flickerOn(e:Event):void

  {

   var ultraAlpha:Number = Math.random() * .9;

   NeonOn.alpha = ultraAlpha;

   if(ultraAlpha>maxFlicker)

   {

    NeonOn.alpha = 1;

    soundControl.stop();

    removeEventListener(Event.ENTER_FRAME, flickerOn);

    addEventListener(Event.ENTER_FRAME, allFlickerOn);

    addtimerTwo();

   }

  }

 

  private function addtimerTwo():void

  {

   timerTwo = new Timer(4000, 0);

   timerTwo.addEventListener(TimerEvent.TIMER, timerTwoEnd);

   timerTwo.start();

  }

 

  private function allFlickerOn(e:Event):void

  {

   var allAlpha:Number = .6 +(Math.random() * .4);

   NeonOn.alpha = allAlpha;

  }

 

  private function timerTwoEnd(e:TimerEvent):void

  {

   timerTwo.stop();

   removeEventListener(Event.ENTER_FRAME, allFlickerOn);

   timerTwo.removeEventListener(TimerEvent.TIMER, timerTwoEnd);

   timerInit();

  }

}

}

This topic has been closed for replies.

5 replies

December 18, 2011

Was reading this thread and wondering how to implement the classin a way that the text would blink only passing the mouse over.......

kglad
Community Expert
Community Expert
December 18, 2011

:

////////////// the code between the ///'s should be saved in com/kglad and named Neon.as

package com.kglad{

    import flash.filters.GlowFilter;

    import flash.display.DisplayObject;

    import flash.utils.Timer;

    import flash.events.TimerEvent;

    public class Neon {

        public static var instance:Neon;

        private var gf:GlowFilter = new GlowFilter();

        private var t:Timer = new Timer(50);

        private static var dobjA:Array = [];

private var overObj:DisplayObject;

        public static function getInstance():Neon {

            if (instance==null) {

                instance = new Neon( new SingletonEnforcer() );

            }

            return instance;

        }

        public function Neon( pvt:SingletonEnforcer ) {

            t.addEventListener(TimerEvent.TIMER,loopF);

        }

        public function flickerOn(dobj:DisplayObject, col:int, max:int,min:int):void{

            dobjA.push([dobj,col,max,min]);

           dobj.addEventListener(MouseEvent.MOUSE_OVER,overF);

dobj.addEventListener(MouseEvent.MOUSE_OUT,outF);

        }

        public function flickerOff(dobj:DisplayObject):void{

            dobj.filters = [];

            for(var i:int=0;i<dobjA.length;i++){

                if(dobjA[0]==dobj){

dobj.removeEventListener(MouseEvent.MOUSE_OVER,overF);

dobj.removeEventListener(MouseEvent.MOUSE_OUT,outF);

                    dobjA.splice(i,1);

                }

            }

        

        }

private function overF(e:MouseEvent):void{

overObj=e.currentTarget;

t.start();

}

private function outF(e:MouseEvent):void{

overObj=null;

t.stop();

}

       

        private function loopF(e:TimerEvent):void{

           

for(var i:int=dobjA.length-1;i>=0;i--){

                if(dobjA[0]){

if(objA[0]==overObj){

                    gf.color = dobjA[1];

                    gf.blurX = gf.blurY = dobjA[3]+(dobjA[2]-dobjA[3])*Math.random();

                    dobjA[0].filters = [gf];

}

                } else {

                    dobjA.splice(i,1);

                  

                }

            }

        }

    }

}

internal class SingletonEnforcer{}

//////////////////////////////////////////// end of Neon class //////////////////////////////

December 18, 2011

check syntax is ok but when I run the .fla it shows extra character at the end of program in this line and appear the swf but mouse over doesn' t work

internal class SingletonEnforcer{}

Known Participant
December 17, 2011

kglad, remember how I thought you called me stupid? It was warranted; I never downloaded the sample files - now I understand how the original class works.  But thank's for your help and patience.

kglad
Community Expert
Community Expert
December 17, 2011

you're welcome.

and, i've done more stupid things while programming than possibly anyone on earth.  doing stupid things and being stupid aren't nearly the same and i wasn't even implying that you were doing something stupid. 

i couldn't see how that class was supposed to be used until i looked at the tutorial.  (and then it was pretty disappointing.)

p.s.  if this thread is closed, mark it as answered.  if you have questions, let me know.

Known Participant
December 17, 2011

I would really appreciate any help; this has got me stumped.

kglad
Community Expert
Community Expert
December 17, 2011

you could post a link to the tutorial.

Known Participant
December 17, 2011

Suppose that would help :http://ultravisual.co.uk/blog/2008/11/25/neon-flickering-effect-in-as3-tutorial/

Thanks for the help thus far btw

Known Participant
December 16, 2011

Now I tried to move the class to the top level and I don't any error, but I don't get an effect either

Known Participant
December 12, 2011

before you ask, all my linkage is correct (don't mind "package ActionScript")

kglad
Community Expert
Community Expert
December 12, 2011

use the trace() function to debug.  start by adding a constructor to verify you're instantiating your class.

Known Participant
December 12, 2011

K, tried your advice, on the timeline actions I put the following code and now I'm getting a Error #2136, any ideas what I'm doing wrong?

import ActionScript.Flicker;

var TitleOn:MovieClip = new Flicker();
var TitleOff:MovieClip = new Flicker();

TitleOn.timerInit();