Copy link to clipboard
Copied
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
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
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
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();
}
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
Hi Kglad.
That worked great. Thanks a lot for your help.
-Shawn
Copy link to clipboard
Copied
you're welcome.
Find more inspiration, events, and resources on the new Adobe Community
Explore Now