;

PDA

Click to See Complete Forum and Search --> : How to use a value of a string variable as linkage name of a sound file


newemadzedan
07-07-2008, 02:41 AM
Hi,

I need to use the value of a string variable as a linkage name of the sound imported in the library, I have this code:

var SoundArray:Array=new Array;
SoundArray[0]="S1";
SoundArray[1]="S2";
SoundArray[2]="S3";
var MySound = new SoundArray[0];
B1.addEventListener(MouseEvent.CLICK,PlaySound);
function PlaySound(event:MouseEvent) {
MySound.play(0,0);
}

where S1,S2,S3 is the name of the classes in the linkage name for the 3 sound files in the library.

I get this Error for the highlighted line of code:

TypeError: Error #1007: Instantiation attempted on a non-constructor.
at Untitled_fla::MainTimeline/frame1()

newemadzedan
07-07-2008, 03:46 AM
This is the line of code
var MySound = new SoundArray[0];

cancerinform
07-07-2008, 09:16 AM
var _Class:Object = getDefinitionByName (SoundArray[0]) as Class;
var mySound:Sound = new _Class();

newemadzedan
07-08-2008, 02:07 AM
thanks a lot, you solved my problem