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

Need help with passing a variable in a function

New Here ,
May 08, 2013 May 08, 2013

Hello. I am working on a Flash app that needs to play videos. I have code using netstream that works great for one movie. The problem is I have 3 movies I want to play and I need to figure out how to replace the string variable with the correct path info depending on what button is pushed. I'm thinking this needs to be an array which I have coded but it is not working. Here is the code:

var buttonArray:Array = [chamber.btnV01,chamber.btnV02];

var strSource:Array = ["HiFlow_Conventional_4.mp4","Tool_Less_5.mp4"];

trace (buttonArray)

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

buttonArray.addEventListener(MouseEvent.CLICK, playClicked);

}

function playClicked(e:MouseEvent):void {

// check's, if the flv has already begun

// to download. if so, resume playback, else

// load the file

if(!bolLoaded) {

var clickedIndex:int = buttonArray.indexOf(event.currentTarget);

nsStream.play(strSource[clickedIndex]);

bolLoaded = true;

trace (strSource)

}

else{

nsStream.resume();

}

This is just set for two buttons for testing. I keep getting the "1120: Access of undefined property event." right at the "nsStream.play(strSource[clickedIndex]);" line. The variable strSource is what I am trying to pass different movie paths into, but I am having no luck. Am setting this up right or is there another way to do this? Any help would be much appreciated. Thanks.

-Shawn

TOPICS
ActionScript
847
Translate
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 , May 08, 2013 May 08, 2013

use:

var buttonArray:Array = [chamber.btnV01,chamber.btnV02];

var strSource:Array = ["HiFlow_Conventional_4.mp4","Tool_Less_5.mp4"];

trace (buttonArray)

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

buttonArray.addEventListener(MouseEvent.CLICK, playClicked);

}

function playClicked(e:MouseEvent):void {

// check's, if the flv has already begun

// to download. if so, resume playback, else

// load the file

if(!bolLoaded) {

var clickedIndex:int = buttonArray.indexOf(e.currentTarget);

nsStream.play(st

...
Translate
Engaged ,
May 08, 2013 May 08, 2013

Try trying event.target instead of event.currentTarget - with the way you have it setup event.currentTarget could be something else and thus not a value in your array.

Translate
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 ,
May 08, 2013 May 08, 2013

use:

var buttonArray:Array = [chamber.btnV01,chamber.btnV02];

var strSource:Array = ["HiFlow_Conventional_4.mp4","Tool_Less_5.mp4"];

trace (buttonArray)

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

buttonArray.addEventListener(MouseEvent.CLICK, playClicked);

}

function playClicked(e:MouseEvent):void {

// check's, if the flv has already begun

// to download. if so, resume playback, else

// load the file

if(!bolLoaded) {

var clickedIndex:int = buttonArray.indexOf(e.currentTarget);

nsStream.play(strSource[clickedIndex]);

bolLoaded = true;

trace (strSource)

}

else{

nsStream.resume();

}

Translate
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
Engaged ,
May 08, 2013 May 08, 2013

Ah yep, that was it. I read the code wrong - haha! For some reason I thought the event listener was setup on the parent button container and not the individual button.

Translate
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 ,
May 08, 2013 May 08, 2013

Hi Kglad.

That worked great. Thanks a lot for your help.

-Shawn

Translate
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 ,
May 08, 2013 May 08, 2013
LATEST

you're welcome.

Translate
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