A Flash Developer Resource Site

Results 1 to 8 of 8

Thread: Sound.setTransform not working!

  1. #1
    Junior Member
    Join Date
    Feb 2022
    Posts
    27

    Sound.setTransform not working!

    Hi!
    I have trouble with applying Sound.setTransform to Movieclip which is loaded as the runtime library soundManager (path: MainEngine3_9_2_compact\module\sound).

    It loads MP3 file, and I want to add setTransform to it (to control ONLY movieclip with MP3 in it)
    but instead, after compiling, it applies setTransform to entire ROOT of swf (globally).


    no matter what I've tried, which syntax I've used, it's either not working at all, or transforms the sound of entire document.

    I'll upload the FLA with main document, and also there is FLA and AS of MP3-loading module.

    all in one zip

    https://disk.yandex.com/d/Aw2uP4DXBEvNxg

    here's the code,but it won't tell much of current situation (line 51-53, Main.FLA, Action Layer).

    Code:
    //NOT WORKING!
    var audio_sound:Sound = new Sound(_root.module.soundManager);
    audio_sound.setTransform({ll:100, rl:10, lr:0, rr:0});
    looks perfectly normal, but not working inside this particular document.
    please help!

    PS. I've added the sound at the timeline to right channel as a test, to check if it interferes with global sound Object or not.

  2. #2
    Client Software Programmer AS3.0's Avatar
    Join Date
    Apr 2011
    Posts
    1,404
    Hello,

    The sound seems to be coming from _root, when modifying lr to 100 I can easily notice a change between both speakers:
    PHP Code:
    setTimeout(delay,1)//delay 1ms before applying setTransform.
    function delay(){
    var 
    audio_sound:Sound = new Sound(_root);
    audio_sound.setTransform({ll:100rl:10lr:100rr:0}); 

    Waiting 1ms seems to let it take effect.
    Last edited by AS3.0; 12-21-2022 at 11:37 PM.

  3. #3
    Junior Member
    Join Date
    Feb 2022
    Posts
    27
    I need to transform sound only in _root.module.soundManager object, not in entire root of document

  4. #4
    Junior Member
    Join Date
    Feb 2022
    Posts
    27
    that IS the problem.
    whenever I try to control sound in _root.module.soundManager, it transforms ENTIRE root instead.
    but it shouldn't.

  5. #5
    Client Software Programmer AS3.0's Avatar
    Join Date
    Apr 2011
    Posts
    1,404
    Hello, a good method is to keep more organized & store all of the sounds in an array.



    Inside of main.fla, you can call createSound("digitall_amb_mono") with the linkage name of sound:
    PHP Code:
    var allSounds:Array=new Array();
    function 
    createSound(a){
    var 
    my_sound:Sound = new Sound();
    my_sound.attachSound(a);
    my_sound.start(0,999);
    allSounds.push(my_sound)
    my_sound.setTransform({ll:0rl:0lr:100rr:0});
    }
    function 
    stopAllAudio(){
    for(var 
    i=0;i<allSounds.length;i++){
    allSounds[i].stop();
    }
    }
    function 
    deleteAllAudio(){
    for(var 
    i=0;i<allSounds.length;i++){
    allSounds[i].stop();
    }
    allSounds=new Array();
    }

    createSound("digitall_amb_mono")
    //allSounds[0].setTransform({ll:0, rl:0, lr:0, rr:100});
    //stopAllAudio()
    //deleteAllAudio()

    If you call createSound("digitall_amb_mono") once:
    PHP Code:
    allSounds[0].stop();//stops sound 1 
    If you call createSound("digitall_amb_mono") a second time:
    PHP Code:
    allSounds[1].stop();//stops sound 2 
    Call allSounds[0].setTransform for the first createSound() call:
    PHP Code:
    allSounds[0].setTransform({ll:0rl:0lr:0rr:100}); 
    Call this to stop all sounds:
    PHP Code:
    stopAllAudio()//Loops through each sound in allSounds array and stops it. 
    Call this to stop all sounds & delete them from the array:
    PHP Code:
    deleteAllAudio()//Stops each sound & sets the array position back to 0 for allSounds. 
    If you are not keeping track of the last sound number you attached for allSounds you can call set transform for the latest attachment as so:
    PHP Code:
    createSound("digitall_amb_mono");//Create a new sound not keeping track of how many are currently being played.
    _root.allSounds[_root.allSounds.length-1].setTransform({ll:0rl:0lr:0rr:100});//Modify setTransform for the last sound created. 
    Inside of "Replic.fla"
    PHP Code:
    _root.module.replicManager.initReplic(function(){
    trace("Реплики готовы");
    _root.allSounds[0].stop()//Call this to stop the audio thats inside of main.fla
    }); 
    Inside of the first keyframe for "Main.fla" you left audio you should set the audio for SOUND TEST keyframe to none.
    Attached Images Attached Images
    Last edited by AS3.0; 12-22-2022 at 02:45 PM.

  6. #6
    Client Software Programmer AS3.0's Avatar
    Join Date
    Apr 2011
    Posts
    1,404
    If you have multiple sounds playing at once you can even transform them all in one call by adding this script to "main.fla" along with the script from post #5
    PHP Code:
    function transformAllAudio(a,b,c,d){
    for(var 
    i=0;i<allSounds.length;i++){
    allSounds[i].setTransform({ll:arl:blr:crr:d});
    }
    }

    transformAllAudio(100,10,100,0);//ll:100, rl:10, lr:100, rr:0 
    If you just want to transform the latest sound you attached with createSound("linkage")
    PHP Code:
    _root.allSounds[_root.allSounds.length-1].setTransform({ll:0rl:0lr:0rr:100});//Modify setTransform for the last sound created. 
    To set transform for a specific sound you have playing you can select it by array position:
    PHP Code:
    _root.allSounds[0].setTransform({ll:0rl:0lr:0rr:100});//Modify setTransform for the sound in array position 0. 


    Here is the full audio source for "main.fla":
    PHP Code:
    var allSounds:Array=new Array();
    function 
    createSound(a){
    var 
    my_sound:Sound = new Sound();
    my_sound.attachSound(a);
    my_sound.start(0,999);
    allSounds.push(my_sound)
    my_sound.setTransform({ll:0rl:0lr:100rr:0});
    }
    function 
    stopAllAudio(){
    for(var 
    i=0;i<allSounds.length;i++){
    allSounds[i].stop();
    }
    }
    function 
    deleteAllAudio(){
    for(var 
    i=0;i<allSounds.length;i++){
    allSounds[i].stop();
    }
    allSounds=new Array();
    }
    function 
    transformAllAudio(a,b,c,d){
    for(var 
    i=0;i<allSounds.length;i++){
    allSounds[i].setTransform({ll:arl:blr:crr:d});
    }
    }

    createSound("digitall_amb_mono")//Create a sound.
    //allSounds[0].setTransform({ll:0, rl:0, lr:0, rr:100}); //Transform just for audio at position 0
    //stopAllAudio()//Stop all audio.
    //deleteAllAudio()//Delete all audio and stop it.
    //transformAllAudio(100,10,100,0);//ll:100, rl:10, lr:100, rr:0 //Transform all audio that is currently playing.
    //_root.allSounds[_root.allSounds.length-1].setTransform({ll:0, rl:0, lr:0, rr:100});//Modify setTransform for the last sound created without keeping track of the sound number. 
    Last edited by AS3.0; 12-22-2022 at 03:26 PM.

  7. #7
    Client Software Programmer AS3.0's Avatar
    Join Date
    Apr 2011
    Posts
    1,404
    Ok yeah, I see your main problem, some of the script is still useable though, So I noticed even when loading 2 swf's it will share the audio transform, so I had to produce the sounds manually for each pitch which actually isn't so bad, only the size I have to work on.

    This work around might be good, this is just a small demo, let me know.

    audio transform v1

  8. #8
    Client Software Programmer AS3.0's Avatar
    Join Date
    Apr 2011
    Posts
    1,404
    Hello I have a full working solution:

    Each green mc has a sound object script, & you can adjust the setTransform for them individually by modifying the text field:
    PHP Code:
    onClipEvent(load){
    var 
    snd:Sound = new Sound(this);//Use 'this' as the accessor for sound inside of a movieclip.
    snd.attachSound("sound1.wav");
    snd.start(0,999);


    tracethis.snd.getVolume())

    onEnterFrame=function(){
    snd.setTransform({ll:int(_root.data_field1.text), rl:0lr:0rr:int(_root.data_field3.text)});
    }

    download v2
    Last edited by AS3.0; 01-28-2023 at 05:54 PM.

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