Skip to main content
Participating Frequently
May 8, 2013
Answered

Need help with passing a variable in a function

  • May 8, 2013
  • 2 replies
  • 896 views

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

This topic has been closed for replies.
Correct answer kglad

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

}

2 replies

kglad
Community Expert
kgladCommunity ExpertCorrect answer
Community Expert
May 8, 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();

}

Nabren
Inspiring
May 8, 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.

Participating Frequently
May 8, 2013

Hi Kglad.

That worked great. Thanks a lot for your help.

-Shawn

Nabren
Inspiring
May 8, 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.