Skip navigation
Currently Being Moderated

MP3 Ios External or Internal?

Mar 8, 2013 7:59 AM

Tags: #mp3

I have a Flash movie that plays MP3 files on a button click using this:

 

function btnClick2(event:MouseEvent):void {

//SoundMixer.stopAll();

var mySound:Sound = new Sound();

mySound.load(new URLRequest("MP3s/name.mp3"));

mySound.play();

}

 

It works fine in publish preview, and it will work once published to the IPhone but it seems intermittant. It will not always play for each click. Sometimes double press. Just strange results.

 

Am I better for IOs actually playing it from the local library (some how)?

 

Or is there a better way to get this to work?

Thanks for your help!

 
Replies
  • kglad
    72,251 posts
    Jul 21, 2002
    Currently Being Moderated
    Mar 8, 2013 8:22 AM   in reply to Vendita3

    yes, it would be better to play it from your local library because it will play without a momentary delay that you would expect with loading from iOS. 

     

    import the mp3 to your library, right click it, click properties, tick export for actionscript and assign a class name (eg, MP3).

     

    you can then use:

     

     

    function btnClick2(event:MouseEvent):void {

    //SoundMixer.stopAll();

    var mySound:Sound = new MP3();

    mySound.play();

    }

     
    |
    Mark as:
  • kglad
    72,251 posts
    Jul 21, 2002
    Currently Being Moderated
    Mar 8, 2013 10:11 AM   in reply to Vendita3

    use:

     

     

    assign your sounds class names like whatever_MP3 where whatever matches your button names.  then use:

     

     

    function btnClick2(event:MouseEvent):void {

    var C:Class=Class(getDefinitionByName(event.currentTarget.name+"_MP3"));

    var c:Sound = new C();

    c.play();

    }

    AString.addEventListener(MouseEvent.CLICK, btnClick2);

     
    |
    Mark as:
  • kglad
    72,251 posts
    Jul 21, 2002
    Currently Being Moderated
    Mar 8, 2013 12:33 PM   in reply to Vendita3

    you're welcome.

     
    |
    Mark as:
  • kglad
    72,251 posts
    Jul 21, 2002
    Currently Being Moderated
    Mar 9, 2013 6:22 AM   in reply to Vendita3

    you probably will get the most dramatic result using mousedown instead of click.  with touch devices that's what you should be using anyway.

     

    you could also eliminate two steps by creating all your sound instances before buttons are pressed:

     

    var C:Class;

    var buttonA:Array = [AString,...];

    for(var i:int=0;i<buttonA.length;i++){

    C = Class(getDefinitionByName(buttonA[i].name+"_MP3"));

    this["sound_"+buttonA[i].name]=new C();

    }

     

    .

    .

    .

    function btnClick2(event:MouseEvent):void {

    this["sound_"+e.currentTarget.name].play();

    }

    AString.addEventListener(MouseEvent.MOUSE_DOWN, btnClick2);

     
    |
    Mark as:
  • kglad
    72,251 posts
    Jul 21, 2002
    Currently Being Moderated
    Mar 9, 2013 7:55 AM   in reply to Vendita3

    C = Class(getDefinitionByName(buttonA[i].name+"_mp3"));

     

    should be

     

    C = Class(getDefinitionByName(buttonA[i].name+"_MP3"));

     
    |
    Mark as:
  • kglad
    72,251 posts
    Jul 21, 2002
    Currently Being Moderated
    Mar 10, 2013 9:59 AM   in reply to Vendita3

    attach a screenshot of your library showing the class names assigned to some of your sounds like AString_xxx.

     
    |
    Mark as:
  • kglad
    72,251 posts
    Jul 21, 2002
    Currently Being Moderated
    Mar 11, 2013 3:59 PM   in reply to Vendita3

    change e.currentTarget to event.currentTarget.

     
    |
    Mark as:
  • kglad
    72,251 posts
    Jul 21, 2002
    Currently Being Moderated
    Mar 12, 2013 6:52 AM   in reply to Vendita3

    use:

     

     

     

    var C:Class;

    var buttonA:Array = [AString,BString];

    for(var i:int=0;i<buttonA.length;i++){

    buttonA[i].addEventListener(MouseEvent.MOUSE_DOWN,btnClick2);

    C = Class(getDefinitionByName(buttonA[i].name+"_mp3"));

    this["sound_"+buttonA[i].name]=new C();

    }

     

    function btnClick2(event:MouseEvent):void {

    this["sound_"+event.currentTarget.name].play();

    }

     

     
    |
    Mark as:
  • kglad
    72,251 posts
    Jul 21, 2002
    Currently Being Moderated
    Mar 12, 2013 7:48 AM   in reply to Vendita3

    you're welcome.

     
    |
    Mark as:

More Like This

  • Retrieving data ...

Bookmarked By (0)

Answers + Points = Status

  • 10 points awarded for Correct Answers
  • 5 points awarded for Helpful Answers
  • 10,000+ points
  • 1,001-10,000 points
  • 501-1,000 points
  • 5-500 points