I want to group some objects (movie clips) in a way allowing me program an event that applies to all of the objects.
To be specific, I want to group some buttons in a video player. If the mouse hovers over any one of the buttons, that button’s animation will jump to frame 2. How can I do this?
(I figured there is probably an easier way than programming each individual button to jump to frame 2 on mouse over.)
One way of doing this considering that you have not assigned the buttons instance name sequentially (btn1, btn2 etc), then you can have an array and push all the instance name of the buttons inside that array. After that you can do something like this:
That’s pretty clever.
I’m new to AS, but it seems this would auto-generate a separate function for each object listed in the array, just as if I had written the individual functions myself.
Thank you.
By the way, should I instead really be using AS3 for a video player?
I will be using it primarily to play live streams of pre-recorded videos with Adobe FMS. (like an internet TV network)
Does AS3 provide video-player-related features that would be impossible with AS2? I really don’t know the difference…
I agree with Ziggwies approach even i was thinking about something similar but changed my mind while writing my post.
AS3 is the latest version of Actionscript and has its advantages but do keep in mind that it might take you more time in mastering it as it has a higher learning curve.
If the elements in the array are instance names of the objects and not variables then they need to enclosed as strings (“”), also you would need to pass their full path if they are contained in another movieclip instead of the main timeline.
The objects are not contained within another movieclip. I placed quotes around the instance names in the array, but the objects still do not respond to the functions. Here is my updated code:
//Valid Buttons
var validControls:Array = ["infoButton", "downloadButton", "muteVolButton", "unmuteVolButton", "volumeSlider", "volumeBG", "seeker", "progressBar", "fullscreenButton"];
//On roll over
function buttonRollOver() {
this.gotoAndStop(2);
}
//On roll out
function buttonRollOut() {
this.gotoAndStop(1);
}
//Generate functions
for(var i:Number = 0; i < validControls.length; i++) {
var obj = validControls[i];
obj.onRollOver = buttonRollOver();
obj.onRollOut = buttonRollOut();
}
I tried hard-coding some functions for the infoButton object, and it works just fine…
//On roll over
infoButton.onRollOver = function() {
this.gotoAndStop(2);
}
//On roll out
infoButton.onRollOut = function() {
this.gotoAndStop(1);
}