|
-
How to use a value of a string variable as linkage name of a sound file
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()
-
This is the line of code
var MySound = new SoundArray[0];
-
Senior Member
var _Class:Object = getDefinitionByName (SoundArray[0]) as Class;
var mySound:Sound = new _Class();
- The right of the People to create Flash movies shall not be infringed. -
-
thanks a lot, you solved my problem
Last edited by newemadzedan; 07-08-2008 at 02:26 AM.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|