• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

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

New Here ,
Jul 17, 2012 Jul 17, 2012

Copy link to clipboard

Copied

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!

TOPICS
ActionScript

Views

1.4K

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Community Expert , Jul 17, 2012 Jul 17, 2012

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");

Votes

Translate

Translate
Community Expert ,
Jul 17, 2012 Jul 17, 2012

Copy link to clipboard

Copied

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");

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jul 18, 2012 Jul 18, 2012

Copy link to clipboard

Copied

I changed "varF" to "urlF" on the timeline to match the function. It works perfectly! Thanks!

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jul 18, 2012 Jul 18, 2012

Copy link to clipboard

Copied

you're welcome.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Oct 01, 2012 Oct 01, 2012

Copy link to clipboard

Copied

Hello,

I'm having some trouble with passing a variable from a movieclip timeline to a child movieclip's class.

I've created 7 movieclips on the main timeline and within each of these moviecilps I've create a movieclip named "moreInfo" with the class MoreInfo.as assigned to it. This class simply opens a web url when the movieclip is clicked. I'm trying to reuse this movieclip in each of the 7 parent movieclips by setting the url on the parent movieclip timeline and passing it to the instance of moreInfo. I've followed the thread above and I'm receiving the following error when the instance of moreInfo shows up:

"TypeError: Error #1034: Type Coercion failed: cannot convert "http://wvsokids.org/the-music/elements-of-music/melody.html" to com.musicalbuildingblocks.MoreInfo.

    at MusicalBuildingBlocks_fla::form_mc_21/frame10()

    at flash.display::MovieClip/gotoAndStop()

    at com::NextPage/nextSection()"

I've placed the following on the parent movieclip's timeline:

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

MoreInfo.as

package com.musicalbuildingblocks

{

    import flash.display.MovieClip;

    import flash.events.MouseEvent;

    import flash.net.navigateToURL;

    import flash.net.URLRequest;

    public class MoreInfo extends MovieClip

    {

       

        public var myURL:String;

        public function MoreInfo(urlS:String):void

        {

            myURL = urlS;

           

            this.buttonMode = true;

            addEventListener(MouseEvent.CLICK, onClick);

        }

        private function onClick(e:MouseEvent):void

        {

            navigateToURL(new URLRequest(myURL), "_blank");

            trace(myURL);

        }

       

    }

}

Thanks!

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Oct 01, 2012 Oct 01, 2012

Copy link to clipboard

Copied

use:

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Oct 01, 2012 Oct 01, 2012

Copy link to clipboard

Copied

Thank you for responding. What exacty does "MoreInfo=new MoreInfo" do?

I used the above code and I'm now receiving this error:

ArgumentError: Error #1063: Argument count mismatch on com.musicalbuildingblocks::MoreInfo(). Expected 1, got 0.

    at flash.display::Sprite/constructChildren()

    at flash.display::Sprite()

    at flash.display::MovieClip()

    at MusicalBuildingBlocks_fla::form_mc_21()

    at flash.display::MovieClip/gotoAndStop()

    at com.musicalbuildingblocks::MusicalBuildingBlocks/clickHandler()

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Oct 01, 2012 Oct 01, 2012

Copy link to clipboard

Copied

LATEST

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.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines