A Flash Developer Resource Site

Results 1 to 4 of 4

Thread: How to use a value of a string variable as linkage name of a sound file

  1. #1
    Member
    Join Date
    Jun 2008
    Location
    Amman, Jordan
    Posts
    44

    Question 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()

  2. #2
    Member
    Join Date
    Jun 2008
    Location
    Amman, Jordan
    Posts
    44
    This is the line of code
    var MySound = new SoundArray[0];

  3. #3
    Senior Member cancerinform's Avatar
    Join Date
    Mar 2002
    Location
    press the picture...
    Posts
    13,448
    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. -

  4. #4
    Member
    Join Date
    Jun 2008
    Location
    Amman, Jordan
    Posts
    44
    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
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center