3 Replies Latest reply on Jul 1, 2012 10:27 AM by Amy Blankenship

    ActionScript Issues


      I've made a simple animation in CS6 and tried coding it in both ActionScript 2.0 and 3.0, which is also supposed to have a sound file attached to it which plays all the way through on loop. What i want it to do is play through the movie sequence -once- then loop back to the beginning of the final keyframe or stop at the last frame of the animation layer ( While the sound file continues looping. ). However, for some reason that i can't figure out, it's ignoring all code that goes in - Ignoring the addition of a sound file and continuously looping back to the beginning without playing the sound. And after closing it down and coming back to it, it's refusing to let any actions be entered in any frame but the first saying that Actions can't be applied to it.


      The files are in the link below for anyone who wants to fiddle with them themselves. 




      Any and all help is appreciated, so i can move on from this and avoid this sort of cock up in the future. 



        • 1. Re: ActionScript Issues
          SuhasYogin Adobe Employee

          Moving this thread to Flash-pro General forums.

          • 2. Re: ActionScript Issues
            kglad Adobe Community Professional & MVP

            1.  you cannot apply code to objects when using as3.


            2.  if you want sound to play indepenedent of a timeline, don't add the sound to that timeline


            when coding or creating any application,


            3. create a small part of the application, then test to make sure that part is working correctly.  if not, debug that part of the application


            4.  back to 3 until your application is complete.

            • 3. Re: ActionScript Issues
              Amy Blankenship Level 4

              I couldn't get your download to work, but what I do to get sound files to work somewhat independently of the timeline is I have a SoundPlayer Class I can't share, but I can tell you what it does. It encapsulates the back-and-forth between Sound and SoundChannel as described here http://help.adobe.com/en_US/as3/dev/WS5b3ccc516d4fbf351e63e3d118a9b90204-7d21.html . It takes a Class that extends Sound, and it will create an instance of that Class on the first time its play() method is called. It then provides pause() and stop() methods, and exposes the position of the SoundChannel that is playing or the last used SoundChannel if it is paused. It also redispatches the soundComplete event from the SoundChannel.


              So, where do you get the Sound Class? In my case, I use Embed in Actionscript like this http://nascode.com/2010/02/01/embedding-asset-at-compile-time-in-pure-as3-project/ . You can also get it out of the library. Just make sure the symbol has been embedded prior to when you call for it, such as checking "embed on frame n" or making sure that it exists on a frame prior to where the code will be executed. If you do put it on the stage, make sure the Synch is set to "Event."


              Now that you have your SoundPlayer set up, in the first frame of your timeline (or when it hits the stage http://www.developria.com/2010/04/combining-the-timeline-with-oo.html), call the sound player instance you made and listen to for the soundComplete. Every time that fires, start the sound over. You can either stop the visuals by using a stop() on the timeline or by using an enterFrame listener that will call stop() on that MC when currentFrame = totalFrames.


              Good luck!