Home Tutorials Forums Articles Blogs Movies Library Employment Press

Go Back   ActionScript.org Forums > ActionScript Forums Group > ActionScript 3.0

Reply
 
Thread Tools Rate Thread Display Modes
Old 06-18-2012, 03:04 PM   #1
tommybanana
Registered User
 
Join Date: Oct 2010
Posts: 46
Default Reducing Code by having a variable in an object name

Hi All,
I am using buttons to control which of a range of sounds play at particular frames in a looping timeline.

I have been putting code into the frames like this:
babyGControl = babyG.play(0,0,babyGsomeTransform);
babyAControl = babyA.play(0,0,babyAsomeTransform);
babyCControl = babyC.play(0,0,babyCsomeTransform);
babyDControl = babyD.play(0,0,babyDsomeTransform);
babyEControl = babyE.play(0,0,babyEsomeTransform);

glockG3Control = glockG3.play(0,0,glockA3someTransform);
glockA3Control = glockA3.play(0,0,glockA3someTransform);
glockC3Control = glockC3.play(0,0,glockC3someTransform);
glockD3Control = glockD3.play(0,0,glockD3someTransform);
glockE3Control = glockE3.play(0,0,glockE3someTransform);
and then using buttons to turn the volume of the sounds the user has chosen to 1 and leaving the unchosen sounds at 0 using soundTransform. Eg One button if clicked sets babyAsomeTransform and glockA3someTransform to 1 so the babyA and the glockA3 sounds are heard.

This kind of works but some of the sounds (generally the ones lower down the list) don't play every time they should.

If I have the 'baby' group at the top (as above) the Baby sound chosen will always play but if the user the chooses the lower glock sound in the list (eg glockE3Control ..) it will only play the first time and then only occassionally after.

If I reorder the code it changes which sounds don't play.
I am guessing flash is playing the sounds higher in the list at 0 volume and running out of bandwidth to play the lower sound that is meant to be audible.

So I am thinking I should be able to have only one baby and one glock command in the frame and let the user decide which sound the commands are going to play.

So I made a variable and used that in the name of the soundControl and soundTransform objects eg:
var babyGlockplay:String = new String();
babyGlockplay = "glockD3Control=glockD3.play(0,0,glockD3someTr ansf orm);";
and put babyGlockplay(); into the frame. But that didn't work.

I tried:
var babyGlockplay:String = new String();
babyGlockplay = "glockD3";
and put
babyGlockplayControl=babyGlockplay.play(0,0,babyGl ockplaysomeTransform);
into the frame. Doesn;t work.

I tried:
var babyGlockplay:String = new String();
babyGlockplay = "glockD3";
and put
[babyGlockplay]Control=[babyGlockplay].play(0,0,b[babyGlockplay]someTransform);
into the frame and that didnt work either.

How can I simplify code so that instead of having loads of options some of which are played at volume = 0, I can just have one or two lines of code that lets me play the sound the user has chosen. How can I set a variable and then place it in a line of code so it changes which soundControl or soundTransform objects are being called?

best

tommybanana

PS I hope that makes some kind of sense.....
tommybanana is offline   Reply With Quote
Old 06-18-2012, 03:57 PM   #2
tommybanana
Registered User
 
Join Date: Oct 2010
Posts: 46
Default

I can see that an If statement in each frame testing the variable would be better than what I currently have.

ie

If (babyGlockplay == "glockD3")
{glockD3Control=glockD3.play(0,0,glockD3someTransf orm);
}



Is that the most code efficient way of doing this.

Best

Tommy Banana
tommybanana is offline   Reply With Quote
Old 06-18-2012, 11:55 PM   #3
Sonny
Senior Member
 
Join Date: Aug 2010
Location: Sydney,Australia
Posts: 132
Default

I dont see the big use in using sound transform here in your case. if you just want to play multiple sound channels at the same time cant you use start and stop instead of sound transforms? you still have all the audio playing at any instance and i wouldnt suggest that
Sonny is offline   Reply With Quote
Reply


Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT. The time now is 12:33 AM.

///
Follow actionscriptorg on Twitter

 


Powered by vBulletin® Version 3.8.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Ad Management plugin by RedTyger
Copyright 2000-2013 ActionScript.org. All Rights Reserved.
Your use of this site is subject to our Privacy Policy and Terms of Use.