A Flash Developer Resource Site

Results 1 to 5 of 5

Thread: Preloader => No sound in main MC

  1. #1
    Senior Member fil_razorback's Avatar
    Join Date
    Jul 2005
    Location
    Paris, France
    Posts
    607

    Preloader => No sound in main MC

    Hi flashkit members ^^

    I have got a swf file called PG3.swf which works fine both online and on my comp. This file includes music and sounds.
    I did a preloased for it, here is the preloader code :
    Code:
    this.attachMovie('ld', 'ldmask', 0);
    ldmask._x = -Stage.width;
    LDGFX.setMask('ldmask');
    ldmask.onEnterFrame = function() {
    	this._x = -Stage.width+(((Stage.width-32)*this._parent.introct.getBytesLoaded())/this._parent.introct.getBytesTotal());
    };
    //Starts loading
    this.createEmptyMovieClip("introct", '1');
    loadMovie("PG3.swf", this.introct);
    onEnterFrame = function () {
    	// Over ?
    	if ((this.introct.getBytesTotal() == this.introct.getBytesLoaded()) and this.introct.getBytesTotal()>300) {
    		ldtxt.removeMovieClip();
    		ldfond.removeMovieClip();
    		ldGFX.removeMovieClip();
    		ldmask.removeMovieClip();
    		delete (this.onEnterFrame);
    	}
    };
    The loading bar is ok, everything is ok BUT the PG3.swf doesn't make any sound nor music when running!

    Sum up :
    PG3 : Sound OK
    Preloader => PG3 : no Sound

    By the way, I don't ever use _root so it's not the problem ^^

  2. #2
    Total Universe Mod jAQUAN's Avatar
    Join Date
    Jul 2000
    Location
    Honolulu
    Posts
    2,429
    There doesnt seem to be anything in your code that would affect playback of a loaded swf. How is the sound in PG3.swf set up or initialized?

    The only thing I can think of is maybe not unsetting the mask before you remove it is causeing the error. I wouldnt make sense if that was the fix but its really the only thing I can see that might be in error.

    LDGFX.setMask(null); //put this line before the remove line and be careful with caps, flash is case sensitive now.
    LDGFX.removeMovieClip();

    Have you looked into useing a movieClipLoader object?
    Last edited by jAQUAN; 05-10-2006 at 06:17 PM.

  3. #3
    Senior Member fil_razorback's Avatar
    Join Date
    Jul 2005
    Location
    Paris, France
    Posts
    607
    As you said, this didn't solve anything >_<

    About the sound in PG3.swf :
    The music is played this way :
    Code:
    musique = new Sound();
    musique.attachSound('music');
    musique.start(0, 999999);
    the sounds are played this way :
    Code:
    function playsound(mc, fichier) { //fichier is the french for file
    	this[mc+'sound'] = new Sound();
    	this[mc+'sound'].attachSound(fichier);
    	this[mc+'sound'].start(0, 1);
    	this[mc+'sound'].onSoundComplete = function() {
    		delete this;
    	};
    }
    About movieCLipLoader :
    I tried it once (a few months ago, on an other project) but I couldn't make it work...I'll try again right now.
    Edit :
    I've just done a preloader using MovieClipLoader :
    Code:
    this.attachMovie('ld', 'ldmask', 0);
    ldmask._x = -Stage.width;
    LDGFX.setMask('ldmask');
    //Starts loading
    this.createEmptyMovieClip('cont', 1);
    ecout = new Object();
    mcl = new MovieClipLoader();
    mcl.loadClip("PG3.swf", cont);
    mcl.addListener(ecout);
    ecout.onLoadProgress = function() {
    	temp = mcl.getProgress(cont);
    	ldmask._x = -Stage.width+(((Stage.width-32)*temp.bytesLoaded)/temp.bytesTotal);
    };
    //Over ?
    ecout.onLoadComplete = function() {
    	ldtxt.removeMovieClip();
    	ldfond.removeMovieClip();
    	LDGFX.setMask(null);
    	LDGFX.removeMovieClip();
    	ldmask.removeMovieClip();
    	delete this;
    };
    The problem is exactly the same : the loading happens perfectly but then no sound is played.



    This is weird because except the code I pasted above, nothing controls the sound in PG3.swf >_<
    Last edited by fil_razorback; 05-10-2006 at 07:02 PM.

  4. #4
    Total Universe Mod jAQUAN's Avatar
    Join Date
    Jul 2000
    Location
    Honolulu
    Posts
    2,429
    I gotta finish some stuff for work right now so I cant do the research but I suspect it has something to do with Sound object scope.
    I think that since you dont specify a clip to attach the sounds to, flash assigns the sound object to control sounds at _level0 or _root. A sound object in the root cannot see sounds in the library of a loaded movie. Try adding the 'this' keyword as a parameter.

    Code:
    musique = new Sound(this);
    musique.attachSound('music');
    musique.start(0, 999999);
    
    function playsound(mc, fichier) { //fichier is the french for file
    	this[mc+'sound'] = new Sound(this);  //you might need to use mc here.
    	this[mc+'sound'].attachSound(fichier);
    	this[mc+'sound'].start(0, 1);
    	this[mc+'sound'].onSoundComplete = function() {
    		delete this;
    	};
    }

  5. #5
    Senior Member fil_razorback's Avatar
    Join Date
    Jul 2005
    Location
    Paris, France
    Posts
    607
    Yeepee, it works !
    I don't know why it used not to because I had used _lockroot


    Anyway, thank you very much ^^

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center