Skip navigation
DanEdmonds
Currently Being Moderated

How do I pass a string variable from a movieclip timeline to a url request inside of a class?

Jul 17, 2012 9:22 PM

Tags: #string #actionscript3 #urlrequest

Hello,

 

I've coded an audio player class I'd like to be able to reuse throughout my project to play a different sound in each movieclip. The audio player works great and the sound loads when I request the url from within the class but I'm having trouble requesting the url coded on the parent movieclip's timeline.

 

I have an instance of a movieclip named musicPlayer in 4 different parent movieclips that is linked to a class named MusicPlayer which contains my audio player code.

 

To test, in one of the parent movieclips, I've placed the following code to set the url path to a string variable:

 

var mp3url = "tuba.mp3";

 

Then, in my class I've declared the same variable as a string:

 

public var mp3url:String;

 

and tried passing it to my url request:

 

mp3File.load(new URLRequest(mp3url));

 

I'm then receiving an error: "1151: A conflict exists with definition mp3url in namespace internal."

 

 

As mentioned above, the sound is loaded perfectly when I set the url path to a string variable within my class like so:

 

public var mp3url:String = "tuba.mp3";

 

 

Thank you in advance!

 
Replies
  • kglad
    72,322 posts
    Jul 21, 2002
    Currently Being Moderated
    Jul 17, 2012 9:42 PM   in reply to DanEdmonds

    use a function to pass that variable or you'll have a timing issue:

     

    in your class:

     

    private function urlF(urlS:String):void{

    // declare mp3url in your class

    mp3url=urlS;

    // you can now use mp3url

    }

     

    // on your timeline:

     

    varF("tuba.mp3");

     
    |
    Mark as:
  • kglad
    72,322 posts
    Jul 21, 2002
    Currently Being Moderated
    Jul 18, 2012 6:25 AM   in reply to DanEdmonds

    you're welcome.

     
    |
    Mark as:
  • kglad
    72,322 posts
    Jul 21, 2002
    Currently Being Moderated
    Oct 1, 2012 9:53 AM   in reply to DanEdmonds

    use:

     

    var mInfo:MoreInfo=new MoreInfo("http://wvsokids.org/the-music/elements-of-music/melody.html");

     
    |
    Mark as:
  • kglad
    72,322 posts
    Jul 21, 2002
    Currently Being Moderated
    Oct 1, 2012 12:42 PM   in reply to DanEdmonds

    it creates a MoreInfo instance which is how your MoreInfo class is designed to be used.

     

    the line of code i suggested would not trigger that error if used with the MoreInfo class you showed.

     
    |
    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