SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Zealot samohtwerdna's Avatar
    Join Date
    Jul 2007
    Posts
    151
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    unloading a swf with sound actionscript 3

    hello again,

    I have run into a problem with transferring a as2 fla to as3 because the as2 used mx.Controls.Loader to load an external swf that only contains a song on it to play in the background. in the as2 version they had put a button that would toggle between frame 1 and two of a movie clip to turn on and off the sound.

    I tried to set up my as3 fla similar but the sound will not turn off!
    Code:
    stop();
    			var bgLoader:Loader = new Loader();
    			bg.addChild(bgLoader);
    			var bgURL:URLRequest = new URLRequest("Untitled-1.swf");
    			bgLoader.load(bgURL);		
    
    var s:Number = 0;
    music_btn.addEventListener(
    	MouseEvent.MOUSE_UP,
    	   function(evt:MouseEvent):void {
    		if(s==0){
    		gotoAndStop(2);
    		bgLoader.unload();
    		s++;
    		}else{
    			gotoAndStop(1);
    			s==0;
    		}
    		}
     );
    here is my simple code on frame one of the movie clip.
    Why doesn't unload - turn the sound off?

  2. #2
    SitePoint Guru [Paul Ferrie]'s Avatar
    Join Date
    Oct 2007
    Location
    Glasgow, Scotland, UK
    Posts
    853
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Code Actionscript:
    music_btn.addEventListener(
        MouseEvent.MOUSE_UP,
           function(evt:MouseEvent):void {
            if(s==0){
            gotoAndStop(2);
            bgLoader.unload();
            s++;
            }else{
                gotoAndStop(1);
                s==0;
            }
            }
     );
    should be
    Code Actionscript:
    music_btn.addEventListener(
        MouseEvent.MOUSE_UP,
           function(evt:MouseEvent):void {
            if(s==0){
            gotoAndStop(2);
            bgLoader.unload();
            s++;
            }else{
                gotoAndStop(1);
                s=0;
            }
            }
     );
    .:To me AS is like LEGO, Only for the big Kids :.
    - Site - Blog - Glasgow Flasher
    bringmadeleinehome.com

  3. #3
    SitePoint Zealot samohtwerdna's Avatar
    Join Date
    Jul 2007
    Posts
    151
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Paul,

    I noticed the double == problem and changed it but the swf still does not unload - or if it does the sound somehow keeps going.

    why??

  4. #4
    SitePoint Guru [Paul Ferrie]'s Avatar
    Join Date
    Oct 2007
    Location
    Glasgow, Scotland, UK
    Posts
    853
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    This may shed some light on your problem
    http://www.gskinner.com/blog/archive...e_to_unlo.html
    .:To me AS is like LEGO, Only for the big Kids :.
    - Site - Blog - Glasgow Flasher
    bringmadeleinehome.com

  5. #5
    SitePoint Zealot samohtwerdna's Avatar
    Join Date
    Jul 2007
    Posts
    151
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks for the link!

    whew - that seems pretty dirty!

    I came up with a solution using soundTransformation and it works well the first time through. However, once I've turned the sound off and back on - it doesn't work so well and I get type errors.

    here is what happens:
    first click: output=
    Code:
    0
    and the sound is turned off
    second click: output =
    Code:
    0
    1
    and the sound is back on
    third click: output =
    Code:
    0
    1
    0
    1
    notice the jump! I get an extra trace that should not be there and the sound is still on.
    fourth click: output=
    Code:
    0
    1
    0
    1
    0
    1
    0
    TypeError: Error #1009: Cannot access a property or method of a null object reference.
    	at MethodInfo-103()
    what the hay??

    here is my code:
    PHP Code:
    var bgLoader:Loader = new Loader();
    bg_mc.addChild(bgLoader);
    var 
    bgURL:URLRequest = new URLRequest("Untitled-1.swf");
    bgLoader.load(bgURL);        


    var 
    s:Number 0;
    music_btn.addEventListener(MouseEvent.MOUSE_UP,
         function(
    evt:MouseEvent):void {
            
    trace(s);
            if(
    s==0){
                
    bg_mc.soundTransform = new SoundTransform(0);
                
    bg_mc.soundTransform.volume 1;
                
    s++;
                
    gotoAndStop(2);
            }else{
                
    s=0;
                
    gotoAndStop(1);
            }
        
        }
     ); 
    Any Idea what I'm doing wrong??


Bookmarks

Posting Permissions

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