5 Replies Latest reply on Jan 14, 2013 9:39 AM by belordmedia

    Cool Effect. Moving it from From Action  Script 2 to Action Scrip3 How?? Need help..

    belordmedia Level 1

      Hello

       

      I have found a cool free template made years ago using AS2 (2008)

      I am using Flash CS6 and never really used AS2 and pretty amteur when it comes to action script.

       

      Within this template from FlashMo, there is a very cool effects where 2 speakers vibrate to the background music.

       

      Here is the code on frame 1 in AS2

       

      stop();

      var my_sound:Sound = new Sound();

      my_sound.attachSound("flashmo_music");

      my_sound.start(0, 9999);

      function flashmo_speakers()

      {

                _root.speaker_left._xscale = _root.speaker_left._yscale = random(3) + 100;

                _root.speaker_right._xscale = _root.speaker_right._yscale = random(3) + 100;

      }

      interval_id = setInterval(this, "flashmo_speakers", 50);

       

      on frame 2

       

      stop();

      my_sound.stop();

      _root.speaker_left._xscale = _root.speaker_left._yscale = 100;

      _root.speaker_right._xscale = _root.speaker_right._yscale = 100;

      clearInterval(interval_id);

       

      instance name for the speakers are

       

      speaker_right

      speaker_left

       

      If I change the setting to AS3, I get this erro message

      WARNING: Text field variable names are not supported in ActionScript 3.0. The variable 'txt' used for an unnamed text field will not be exported.

      WARNING: Actions on button or MovieClip instances are not supported in ActionScript 3.0. All scripts on object instances will be ignored.

      WARNING: Text field variable names are not supported in ActionScript 3.0. The variable 'txt' used for an unnamed text field will not be exported.

       

       

       

      Can someone recreate it in AS 3???

       

      Many thanks

       

      Michael

        • 1. Re: Cool Effect. Moving it from From Action  Script 2 to Action Scrip3 How?? Need help..
          kglad Adobe Community Professional & MVP

          :

           

           

           

          stop();

          var my_sound:Sound = new FlashMoSound();   // assign class FlashMoSound instead of linkage id flashmo_music

          var sc:SoundChannel=my_sound.play(0, 9999);

          function flashmo_speakers()

          {

                    MovieClip(root).speaker_left.scaleX = MovieClip(root).speaker_left.scaleY = 1+Math.floor(Math.random()*3)/10;

                    MovieClip(root).speaker_right.scaleX = _root.speaker_right.scaleY =1+Math.floor(Math.random()*3)/10;

          }

          var interval_id:int = setInterval(this, "flashmo_speakers", 50);

           

          on frame 2

           

          stop();

          sc.stop();

          MovieClip(root).speaker_left.scaleX = MovieClip(root).speaker_left.scaleY = 1;

          MovieClip(root).speaker_right.scaleX = MovieClip(root).speaker_right.scaleY = 1;

          clearInterval(interval_id);

           

           

           

          1 person found this helpful
          • 2. Re: Cool Effect. Moving it from From Action  Script 2 to Action Scrip3 How?? Need help..
            sinious Most Valuable Participant

            The Sound class is slightly different. On the sound in the library you have to right-click on the audio, select properties, hit the ActionScript tab and select to Export for ActionScript. In the "Class" field below give it a valid unique class name, any name you'd like, e.g. "FlashmoMusic". Then you can access the sound from AS3.

             

            To instantiate the embedded sound via the AS3 sound class (tutorial here) you just do like so:

             

            import flash.media.SoundChannel;

             

            var my_audio:FlashmoMusic = new FlashmoMusic(); // change this to the name you assign

            var my_sound:SoundChannel = my_audio.play(0,9999);

            Your audio should now be playing.

             

            The speakers could be more interesting, based on actual sound information at various EQ ranges with AS3. I'm just informing you that AS2 could not directly read the wave data in a simple way while AS3 could. The speakers could be programmed in AS3 to only appear to vibrate along with the volume being outputted. Outside that, I'll stick to just what your AS2 was doing, which was just making them move based on a random variable.

             

            import flash.utils.Timer;

            import flash.events.Event;

            import flash.events.TimerEvent;

             

            var speakerTimer:Tiemr = new Timer(50,0);

            speakerTimer.addEventListener(TimerEvent.TIMER, onTimer);

            addEventListener(Event.ENTER_FRAME, onEF);

             

            function onEF(e:Event):void

            {

                 removeEventListener(Event.ENTER_FRAME, onEF);

                 speakerTimer.start();

            }

             

            function onTimer(e:TimerEvent):void

            {

                 speaker_left.scaleY = speaker_left.scaleX = Math.random()*.3 + 1;

                 speaker_right.scaleY = speaker_right.scaleX = Math.random()*.3 + 1;

            }

             

            To stop the sound and shaking on frame 2, just run:

             

            speakerTimer.stop();

            speaker_left.scaleX = speaker_left.scaleY = 1;

            speaker_right.scaleX = speaker_right.scaleY = 1;

            my_audio.stop();

             

            Edit:

             

            Oy.. I need to stop writing explainations, you beat me every time

            1 person found this helpful
            • 3. Re: Cool Effect. Moving it from From Action  Script 2 to Action Scrip3 How?? Need help..
              belordmedia Level 1

              Hi guys and girls,

               

              you are so great.

               

              Will give this a serious go.

               

              Will keep you informed if it works.

              Think I will need to start from scratch. To much AS2 for me.

               

              Probably will run into more problems and will beg for your help again

               

              not sure if I can do that but here is a link of the file

              http://www.flashmo.com/preview/flashmo_086_speaker

               

              Its free and, I really like the retro style of some components.

               

              I am seen a doctor right now...

               

              Peace

              • 4. Re: Cool Effect. Moving it from From Action  Script 2 to Action Scrip3 How?? Need help..
                sinious Most Valuable Participant

                You may just want to check with the place you downloaded the AS2 source to see if they have AS3 source.

                 

                What that AS2 is doing is playing audio and randomly scaling a graphic of a left and right speaker randomly. Both of those are separate things and easy to do on their own. That's why I broke out what you're doing into chunks of 1) playing the sound from library, 2) animating the speaker, 3) stopping it all on frame 2.

                 

                Very basic AS3 code, but 2 different simple things.

                1 person found this helpful
                • 5. Re: Cool Effect. Moving it from From Action  Script 2 to Action Scrip3 How?? Need help..
                  belordmedia Level 1

                  Hello Again

                   

                  Not working. Missing somthing. Could be brain.grrr

                  So, Need some more help I think

                   

                  Got a  a brand  new project in flash.

                   

                  On the stage I have

                  2X movie clips of speaker left and speaker right

                  Instance names are

                   

                  speaker_left

                  speaker_right

                   

                  one button. Music is on/Music is Off

                  No instance name.

                   

                  That is it

                   

                  Can you please once again put me on the right path?

                   

                  Kind Regards

                   

                   

                  M