Sound doesn't play from an mc when loaded using moviecliploader

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • chromis
    New Member
    • Jan 2008
    • 113

    Sound doesn't play from an mc when loaded using moviecliploader

    Hi,

    I've been struggling to get sounds to work with attachSound when the sounds are stored in a swf loaded into another swf. I came across a post on a forum which supposedly explains how to to do it, however i tryed what it suggested and it doesn't work. (link)

    I then tryed to use the MovieClipLoader class so that once the swf was loaded the sound would be played. What is strange though is that when the swf has loaded i can return a valid reference to the sound object, but cannot play it. This is all local, so it should play. I'm very confused.

    Here is my code:
    sound.swf - beep_sound.wav file is in the library with linkage identifier beep_sound
    Code:
    _global.my_beep_sound = new Sound();
    my_beep_sound.attachSound("beep_sound");
    trace("Sound file loaded"+my_beep_sound);
    player.swf
    Code:
    // create an empty movie clip
    this.createEmptyMovieClip("my_mc", this.getNextHighestDepth());
    
    // Create Movie clip loader for sound
    var my_mcl:MovieClipLoader = new MovieClipLoader();
    var mclListener:Object = new Object();
    
    // Setup events for preloader
    mclListener.onLoadStart = function(target_mc:MovieClip):Void {
    };
    mclListener.onLoadProgress = function(target_mc:MovieClip, numBytesLoaded:Number, numBytesTotal:Number):Void {
    };
    mclListener.onLoadComplete = function(target_mc:MovieClip):Void {
    };
    mclListener.onLoadInit = function(target_mc:MovieClip):Void {
    	trace("init");
    	trace(my_beep_sound);
            my_beep_sound.start(0,999);
    };		
    my_mcl.addListener(mclListener);
    
    // Load sound
    my_mcl.loadClip("sound.swf",my_mc);
    The trace output is:
    Code:
    Sound file loaded: [object Object]
    init
    [object Object]
    Thanks,

    Chromis
  • Markus
    Recognized Expert Expert
    • Jun 2007
    • 6092

    #2
    When you create your new sound object, try doing:

    Code:
    new Sound(this)

    Comment

    • chromis
      New Member
      • Jan 2008
      • 113

      #3
      Hi Marcus,

      Can't tell you how pleased I am you've sorted that out for me, thanks! Was really stuck on that one. So does that change the timeline for the sound to the the containing mc? What is it otherwise?

      Thanks again,

      Chromis

      Comment

      • Markus
        Recognized Expert Expert
        • Jun 2007
        • 6092

        #4
        No that doesn't work. Here's a discussion on the problem that seems to explain it pretty well (and offers a solution too).

        Comment

        • chromis
          New Member
          • Jan 2008
          • 113

          #5
          I did have a look at that whilst i was researching the issue, it's not really the way i wanted to go about it though as on the actual project that has the issue I've got a moviecliploader which loads the main swf. Your solution above worked a treat though. What's strange is I would assume the sound constructor to take the movieclip it's in as a target as default. Instead it seems to be the current root right?

          Comment

          • Markus
            Recognized Expert Expert
            • Jun 2007
            • 6092

            #6
            Oops, I hadn't seen your reply before I made my second post. Sorry about that.

            Yes, I would've thought the object would default to the movie clip / button it's in - of course, your's isn't in a movie clip or button.

            Time to do some research :D

            Also, don't double post your question :P

            Glad I could help,
            Markus.

            Comment

            • chromis
              New Member
              • Jan 2008
              • 113

              #7
              Sorry about the double post, although technically it's not the same question, more of a development from the previous one ;)

              Thanks again for you help.

              Comment

              • Markus
                Recognized Expert Expert
                • Jun 2007
                • 6092

                #8
                Originally posted by chromis
                Sorry about the double post, although technically it's not the same question, more of a development from the previous one ;)

                Thanks again for you help.
                Sure, but while it's an extension of this question, it still largely relates to this thread. So, no need to create a new thread, although I won't hold it against you.

                See ya around,

                Markus.

                Comment

                • chromis
                  New Member
                  • Jan 2008
                  • 113

                  #9
                  Haha fair play, I'll remember that in the future.

                  Chromis

                  Comment

                  Working...