Home Tutorials Forums Articles Blogs Movies Library Employment Press

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

Reply
 
Thread Tools Rate Thread Display Modes
Old 07-11-2007, 08:09 PM   #1
2slow
Registered User
 
Join Date: Jun 2007
Posts: 26
Default Can I declare a variable with another variable

Here is what I want to do. Within a function that has been passed two arguments I want to declare a sound object variable as one of those arguments. So far no go.

Here is the code
function DeclareSound(Sound_ID:String, mc:String):Void {
trace(Sound_ID);
var Sound_ID:Sound = new Sound(mc);
Sound_ID.attachSound("Blues Guitar");
sSound_ID.start(0,1000);
}
2slow is offline   Reply With Quote
Old 07-11-2007, 08:25 PM   #2
Cota
Super Moderator
 
Cota's Avatar
 
Join Date: Jul 2001
Location: NYC
Posts: 10,175
Default

Something like
ActionScript Code:
this[Sound_ID] = new Sound(mc);
__________________
Color Wars | (kul′ər wrs) n. - Open conflict between factions. www.theColorWars.com

cota - www.chadworkman.com | http://shavedplatypus.com
occupation: designer | flash developer | server-side developer (php, asp, mssql, mysql)
Cota is offline   Reply With Quote
Old 07-11-2007, 08:28 PM   #3
xxneon
Super Moderator
 
xxneon's Avatar
 
Join Date: Dec 2006
Location: Amish Country, PA
Posts: 8,570
Send a message via ICQ to xxneon Send a message via AIM to xxneon Send a message via MSN to xxneon Send a message via Skype™ to xxneon
Default

ActionScript Code:
function DeclareSound(Sound_ID:String, mc:String):Void { trace(Sound_ID); var s:Sound = _root[Sound_ID] = new Sound(mc); s.attachSound("Blues Guitar"); s.start(0,1000); }

this creates a variable at root .. and assigns it to a variable that is declared into the function so 's' in effect is '_root[Sound_ID]'.. i mainly did this to save me from typing '_root[Sound_ID] three times.. just looks cleaner..

but then now you have a sound variable at the _root level that you can access at any time after the the function creates the sound object..
xxneon is offline   Reply With Quote
Old 07-11-2007, 08:31 PM   #4
2slow
Registered User
 
Join Date: Jun 2007
Posts: 26
Default thanks

Thank you
This will save hours of cut and paste.

Now I just need to conquer the whole record an mp3 with flash obstacle.
2slow 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 Off
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
LP Colorpicker biosonik Components 0 03-25-2005 06:37 AM
Simplify wyclef ActionScript 1.0 (and below) 26 07-01-2003 05:17 AM
Variable musings retrotron ActionScript 1.0 (and below) 8 06-24-2003 10:33 PM
strange variable behavior flashdudette ActionScript 1.0 (and below) 3 05-09-2003 06:49 PM
checking variable problem flashdudette Server-Side Scripting 0 04-29-2003 05:51 PM


All times are GMT. The time now is 04:12 PM.

///
Follow actionscriptorg on Twitter

 


Powered by vBulletin® Version 3.8.5
Copyright ©2000 - 2014, 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.