PDA

View Full Version : How to disable a button/action after a single click?


DaForce2000
05-04-2008, 01:57 PM
So what im trying to do is have a few buttons that when pressed go to and play a movie symbol at keyframes throughout the timeline.

Say there was a picture of a man, and you click button A and the picture zooms in on the mans head, button B zooms in on his hand and button C zooms in on his foot.
I have all the motion tweening setup and all the buttons work via AS3 using gotoandplay, and there is a stop at each step of the way.

Thats all fine, it works perfectly, however the only issue I have is, say you click button A it plays the part that zooms in on his head, but if you click A again buring the tween/playback it goes back and starts playing again.
Basically what im after, is once you click a button, it becomes no longer clickable untill it gets to next step.
I can disable the button symbol itself using the buttonA.enabled=false; but as the script is on a seperate layer, that doesnt do anything at all. It just stops the button from being a button.. the area ist sitll clickable due to the script. And you cant put scripts within the buttons themselves.

The script im using is
menubutton1.addEventListener(
MouseEvent.MOUSE_UP,
function(evt:MouseEvent):void {
gotoAndPlay(2);
}
);

So is there anyway of disabling the gotoand play function between the keyframes. So that if the button is clicked during the tween/playback it doesnt do anything?
I have tried putting a script on the next frame, that doesnt have the gotoandplay portion but that didnt do anything.

(sorry thats a right mess, hope it all makes sense.)

MSFX
05-04-2008, 02:17 PM
you can just remove the event listener once you have used it once by having a remove statement within you listener function like this...

menubutton1.addEventListener(MouseEvent.MOUSE_UP, up);

function up(evt:MouseEvent):void
{
menubutton1.gotoAndPlay(2);
menubutton1.removeEventListener(MouseEvent.MOUSE_U P, up);
}


As you can see the remove statement is IDENTICAL except for the key word remove...

I changed the format so it was easier for you to follow...

To add the listener back just repeat the intial code wherever you wish for it to be... or more efficiently wrap it up in a function and just call the function whenever you need it...

Mazoonist
05-04-2008, 02:40 PM
First of all, don't write the function as an anonymous, inline function like that. If you do, there is no way to turn off that listener with removeEventListener. Secondly, there are many ways to go about doing what you're after (the way you set it up can differ in the details), but I suppose the basic technique is the same. When a button is clicked, remove its event listener while making sure all the others are still active. Here's an example where the buttons (or movie clips acting as buttons, doesn't matter) are on the stage and named b1, b2, and b3. Notice the same event handler function can be applied to all three, and you can detect which one was clicked using event.target:
b1.addEventListener(MouseEvent.MOUSE_DOWN, handler);
b2.addEventListener(MouseEvent.MOUSE_DOWN, handler);
b3.addEventListener(MouseEvent.MOUSE_DOWN, handler);

function handler(event:MouseEvent):void {
b1.addEventListener(MouseEvent.MOUSE_DOWN, handler);
b2.addEventListener(MouseEvent.MOUSE_DOWN, handler);
b3.addEventListener(MouseEvent.MOUSE_DOWN, handler);
b1.alpha = 1;
b2.alpha = 1;
b3.alpha = 1;
event.target.removeEventListener(MouseEvent.MOUSE_ DOWN, handler);
event.target.alpha = 0.5;
}

The alpha of the disabled button is set to half just so that you can see the effect when you run it. I said there were many ways to set this up. The above is kind of brute force. If you had a ton of buttons you would want to put them in an array and use a loop to process them instead.

Mazoonist
05-04-2008, 02:45 PM
Here's the array approach. Now you could have any number of buttons (just add their instance names to the array's list) and it will all still work:
var bArray:Array = [b1, b2, b3];

for (var i:int = 0; i < bArray.length; i++) {
bArray[i].addEventListener(MouseEvent.MOUSE_DOWN, handler);
}

function handler(event:MouseEvent):void {
for (var i:int = 0; i < bArray.length; i++) {
bArray[i].addEventListener(MouseEvent.MOUSE_DOWN, handler);
bArray[i].alpha = 1;
}
event.target.removeEventListener(MouseEvent.MOUSE_ DOWN, handler);
event.target.alpha = 0.5;
}

MSFX
05-04-2008, 03:08 PM
phoar nice one Maz ;) spesh like the

e.target.removeEventListener(MouseEvent.MOUSE_DOWN , handler);

hadnt thought of that before :o

DaForce2000
05-05-2008, 12:41 AM
Woah, nice.
Thanks lads :)

I have tested with menubutton1.mouseEnabled = false; and that seems to do exactly what im after.

However I am keen to try out what you have provided.
Mazoonist, Quick question.. where would the gotoandplay go in your 2 examples?

...please excuse any stupid questions, pretty much a newb to AS3.. and most sorts of script/code TBH

MSFX
05-05-2008, 10:58 AM
who says we're lads :p lol (I am btw lol)

With Mazzies :p example if your using the array its best to have your gotoAndPlay() locations within an array as well...


var bArray:Array = [b1, b2, b3];
var gtArray:Array = ["add frame labels like this", 5, "<-or frame numbers like that"];

for (var i:int = 0; i < bArray.length; i++)
{
bArray[i].addEventListener(MouseEvent.MOUSE_DOWN, handler);
}

function handler(event:MouseEvent):void
{
for (var i:int = 0; i < bArray.length; i++)
{
bArray[i].addEventListener(MouseEvent.MOUSE_DOWN, handler); bArray[i].alpha = 1;
}

event.target.removeEventListener(MouseEvent.MOUSE_ DOWN, handler); event.target.alpha = 0.5;
// return the character at the end of the button name to access the index within the array (after minusing 1)
gotoAndPlay(gtArray[e.currentTarget.name.charAt(1)-1]);
}

I know the end of that is rather complicated, it may not run I dont have flash on this machine so cant test it. If someone wants to simplify it then I would love to see a more efficient way.... :)

amarghosh
05-05-2008, 11:39 AM
First of all, don't write the function as an anonymous, inline function like that. If you do, there is no way to turn off that listener with removeEventListener.

i wanted to add a listener for the first time a sprite was added to stage and this did work for me (though i agree that its an odd way of doing it)
//
sprite.addEventListener(Event.ADDED_TO_STAGE, function(e:Event):void
{
trace("anonymous");
sprite.removeEventListener(Event.ADDED_TO_STAGE, arguments.callee);
});

Mazoonist
05-05-2008, 12:40 PM
Wow. Thanks, armagosh, I had no idea that there was a way to do that.

See page 217 of Essential Actionscript 3.0 (Colin Moock)

Mazoonist
05-05-2008, 01:24 PM
DaForce,

Let's say you have a button that controls a separate MovieClip. You add an event listener to the button, then you write a function that handles the event. First you need to decide which event is appropriate: Do you want the action to happen when the mouse button goes down, when it comes up, or both? These events are MOUSE_DOWN, MOUSE_UP, and CLICK. I would use CLICK myself, it's the easiest and doesn't activate unless someone releases the mouse button while still hovering the button.

Next, decide what you want to have happen when that button is CLICKed. You want two things to happen. First, the button won't receive another CLICK. You know how to do this now, either turn off the listener, or use mouseEnabled=false. Secondly, you want to tell the movie clip that's being controlled by the button to gotoAndPlay or gotoAndStop on one of its frames.

I can't see your project or your code, but I can tell you that programming buttons is a matter or working out the logic of what you want to have happen when, and in response to what event. There's nothing wrong with writing this logic out in plain english beforehand. Then it's just a matter of translating that to Actionscript.

Example:
When the button is CLICK ed;
Don't allow another CLICK on it right away
Make instanceName (a MovieClip) goto and play its frame 2 (or whatever).

DaForce2000
05-05-2008, 02:16 PM
Awesome info many thanks all 3 of you!!

I had to rush out that part of it last night, so I kinda bodged together some new code and my old code, which i got working exactly how I wanted.
Yeah it sure is bloated, and probably all wrong.. but in short it works. Not too bad given its my first go at AS3.
In the next day or 2 I will go thru what you guys have posted and re-do it properly. As im keen to learn more

This is what I ended up using for the 3 buttons, its basically copied onto each of the necessary keyframes, and the gotoandplay frames are changed.

menubutton1.mouseEnabled = true;
menubutton2.mouseEnabled = true;
menubutton3.mouseEnabled = true;
menubutton1.addEventListener(
MouseEvent.MOUSE_UP,
function(evt:MouseEvent):void {
gotoAndPlay(2);
menubutton1.mouseEnabled = false;
menubutton2.mouseEnabled = false;
menubutton3.mouseEnabled = false;
}
);
menubutton2.addEventListener(
MouseEvent.MOUSE_UP,
function(evt:MouseEvent):void {
gotoAndPlay(107);
menubutton1.mouseEnabled = false;
menubutton2.mouseEnabled = false;
menubutton3.mouseEnabled = false;
}
);
menubutton3.addEventListener(
MouseEvent.MOUSE_UP,
function(evt:MouseEvent):void {
gotoAndPlay(123);
menubutton1.mouseEnabled = false;
menubutton2.mouseEnabled = false;
menubutton3.mouseEnabled = false;
}
);


I know its all busted up and not proper, but I really needed to get it working there and then, I will fix it up and make it proper in the next day or 2, for now it does the job just fine.
Many many thanks for all your helps. Very appreciative of all of it, and I promise you it will be put to go use :)

DaForce2000
05-07-2008, 02:07 AM
ok, one final question. Its still sort of relevant to this so I wont post another thread about it.

I have a 4 buttons which are placed in a symbol (movie clip) all with unique instance names. (2 buttons, which are copied twice)
And that symbol is on the stage being animated by the buttons I mentioned in my previous posts.

Currently the AS that controls these buttons is in an actions layer within the symbol.. so basically nested in one level from the stage, as the symbol is on the stage.

I want to be able to disabled the buttons, the same way i disabled the menu buttons (see previous posts) using mouseenabled = false, however I get a 1120: Access of undefined property mybutton when trying to disabled the buttons within the symbol.
The AS for disabling these buttons is in the stage timeline alone with the AS posted above.
So I assume I need to tell it to look for the buttons within the symbol, as it cant find those instance names on the stage as they are within the symbol.

Whats the easiest way around this problem. Ideally without changing the existing code as I dont really have the time for that at the moment.

Many thanks!! :)

Mazoonist
05-07-2008, 03:14 AM
Give the outer MovieClip symbol an instance name also. Let's suppose you called it "clip," then the command to disable a button inside of it would look like this:
clip.button1.mouseEnabled = false;
Substitute your own instance names, of course. The idea is that you can use dot notation to write the path to the nested object(s). And actually, the full (and more verbose) path would be:
this.clip.button1.mouseEnabled = false;
"this" in the above means the main timeline. However, you're allowed to not include it and flash will assume it. Hope that helps.

DaForce2000
05-07-2008, 03:24 AM
ahhh sweet, perfect!!!

Still learning the basics :)

Many thanks.
I think that should be enough to get this thing done.

I will have to haunt this place more often.

DaForce2000
05-10-2008, 01:30 PM
One more final thing.

Again as its all related to this current project, i will post it here, and seeing the existing code will help.

I was wondering whats the easiest way to have part of the timeline play in reverse.
So instead of clicking on one of the buttons and having it goto frame X and playing until it hits a stop(), I would like it to go to frame X and play in reverse until it hits a stop()

You can see the code above I use which is on each step (every 15 frames or so) and the buttons change where they gotoandplay.

Currently I have just made a tween that basically plays as if it were going backwards. Which works just fine. But requires twice as many tweens to be created. If I can accomplish this with a fairly simple script that would make things alot quicker.
I will be having around 8 or so "steps" which all need to be able to tween to each other. So thats alot of tweens I gotta make, and cutting that in half would be a big help.
A -> B
A -> C
A -> D
A -> E
A -> F
A -> G
B -> A
B -> C
B -> D
etc...etc..etc..

Any examples that could provided (ideally based of my current script) would be fantastic, if not possible with my current script, if examples could be provided and I can look into changing what I am already using.

Many many thanks!!

Mazoonist
05-10-2008, 02:33 PM
DaForce2000,

You might write a function that plays the timeline backwards from any frame to any frame, using the ENTER_FRAME event, like so:
function playBackwards(startFrame:int, endFrame:int):void {
var counter:int = startFrame;
gotoAndStop(startFrame);
addEventListener(Event.ENTER_FRAME, reverse);
function reverse(event:Event):void {
counter--;
gotoAndStop(counter);
if(currentFrame == endFrame) {
removeEventListener(Event.ENTER_FRAME, reverse);
}
}
}
Then, suppose you wanted to play the timeline backward starting at frame 20 and ending at frame 1, you could call this function like so:
playBackwards(20, 1);
You could make this function call in response to whatever you want. Here's some code to call it in response to a click anywhere on the stage:
stage.addEventListener(MouseEvent.CLICK, clickHandler);
function clickHandler(event:MouseEvent):void {
playBackwards(20, 1);
}

DaForce2000
05-11-2008, 01:55 AM
Very nice.

So let me just undetrstand this. The function code needs to go at the top of the AS on any keyframe that will use a button to call the playbackwards function?
So on each "step" i need a new copy of it?
But as its a function I dont need to change anything with in that, just the frame numbers when i use playbackwards (x,y) ?

Then you only need to add in the playbackwards (X, y) where say gotoandplay would normally be on a button that I want to play backwards.

Many thanks!!

DaForce2000
05-12-2008, 09:51 AM
Mazoonist,

ok, it works pretty well except it doesnt seem to be removing the listener, as my first button which i call playBackwards(29, 15); then always does that.
If i read the function correctly, when it reaches frame 15 it should remove the listener, and the button should react according to the AS on frame 15, which is simply gotoAndPlay(15); so that it doesnt actually do anything. However when click it plays backwards from 29-15 again.

Here is the script on that frame (frame 30) excluding the 2 other buttons which im not playing with yet.

menubutton1.mouseEnabled = true;
menubutton1.addEventListener(
MouseEvent.MOUSE_UP,
function(evt:MouseEvent):void {
playBackwards(29, 15);
menubutton1.mouseEnabled = false;
}
);


And then on frame 15 its the same except has gotoandplay(15) instead of the playbackwards, except its still running the playbackwards function.

The function code is in the first keyframe.

Come to think of it since there are 2 other buttons which could lead the playback to another frame other than the endframe, there needs to be another way of removing the listener, perhaps once any button is pressed on that frame. I tried that, but it gave me an undefined error.

Seems if I put removeEventListener(Event.ENTER_FRAME, reverse); anywhere, I get "1120: Access of undefined property reverse.". Its in the function, but it doesnt seem to be working, as as far as I can tell the eventlistener is not being removed as that button gets locking in to always calling that same playBackwards(29, 15);

Mazoonist
05-12-2008, 12:56 PM
I usually don't "nest" functions, but in the above case I did, so that I could keep the handler in the same scope as my counter variable. So you are learning about scope here. The removeEventListener line won't work anywhere else outside of the function that contains the enterFrame handler, because since it was defined inside the function, it's local to the function.

Let's separate it, then. Now the reverse function will be a separate function, no longer nested inside the playBackwards function. But now it will be necessary to separate the counter variable, too, so that both functions can use it. Also, it will be necessary to separate the endFrame variable, too, since it's sent to the first function but used within the body of the second function:
var counter:int;
var endFrame:int;

function playBackwards(startFrame:int, endFrame:int):void {
counter = startFrame;
gotoAndStop(startFrame);
addEventListener(Event.ENTER_FRAME, reverse);
}
function reverse(event:Event):void {
counter--;
gotoAndStop(counter);
if (currentFrame == endFrame) {
removeEventListener(Event.ENTER_FRAME, reverse);
}
}
When you place a function on frame 1 it remains active throughout the timeline, there's no need to put multiple copies of the script on the various frames. However, coding on the timeline can be tricky, as when the playhead visits various frames, code on those frames is run again. So the whole thing must be carefully crafted, and I believe you would ditch the whole timeline approach if you knew what the tween class can do. But I understand you have a project to expedite.

DaForce2000
05-12-2008, 01:07 PM
Many thanks, I will give that a shot on the morrow.
I will put it in frame one, but shift all the animations forward a frame, so the function cannot be run more than once. Thanks for the tip.

I was infact thinking about the possibility of scripting the tweens or using a tween class type of thing the other day, but put it to the back of my mind in order to get this done.
I would be very interested in learning that once I get this done. If you have any handy information or links, that you could provide that would be brilliant.

I really appreciate all your help. If you ever to come Australia, I will buy you a beer or a drink of your preference :)

DaForce2000
05-12-2008, 01:43 PM
Hmm just tried it.

replaced the function code in the first frame with the new un-nested code(for now as the tests im doing dont require the play head to go back to frame1.

And when pressing the button that calls for playbackwards, it ignores the end frame and goes all the way back to the first frame, ignoring various stop()'s along the way.
Then the other 2 buttons dont work anymore, and the 1st button still plays thru that entire loop each time its pressed.

Any idea what im doing wrong :(

Mazoonist
05-15-2008, 03:02 AM
Is there any way you could send me your file? It'd be nice to see the fla, working or not, that contains the problem.

DaForce2000
05-15-2008, 11:42 AM
Have just PM'd you the files.

Its a pure test flie, so it looks crap. So just ignore that ;)

The function file is my test with the recent reverse function. And I think most of the frames that need to be reversed use that function, but dont seem to remove the listener properly as you can just keep clicking the button and it plays over and over instead of using the AS on that frame. I have added an extra removeeventlistener on each AS keyframe frame, but hasn't help AFAIK.
The extra reverse tweens are still in the timeline as I havn't cleared them up as its not really working yet.

The other file, is just what I had before, all done via tweens, a forward tween and a reverse tween. Simple but more work. Thats how it "should" work.

I hope it makes sense, its abit of a mess but the original file works perfectly but means making more tweens. If the reverse function worked it would save some tween creations.
(not worrying about the tween class ATM, but that would be probably the best solution)

Thanks mate.

Mazoonist
05-16-2008, 12:58 AM
When you place a function on frame 1 it remains active throughout the timeline, there's no need to put multiple copies of the script on the various frames.
What part of that did you not understand? You've got copies of the same script scattered throughout the timeline. I'll fix it and get back with you. :cool:

DaForce2000
05-16-2008, 01:09 AM
What part of that did you not understand? You've got copies of the same script scattered throughout the timeline. I'll fix it and get back with you. :cool:

haha yeah I realise that.

That was an attempt to make it work, but adding the removeeventlistener to the beginning of each frame.

I first tried with just the function at frame1 and then just the playbackwards() on the keyframes that require it. Same thing still happened... as far as I can recall.

Mazoonist
05-16-2008, 02:21 AM
DaForce,

See if this makes any sense to you. In the attached file, I put all of the code on frame 1, and yet it controls the whole timeline. I re-instated my original playBackwards function that I gave you, as there was nothing wrong with it, I think you just used it wrong. The function takes care of removing its own ENTER_FRAME listener.

I made a similar playForwards function. This way, the stop commands along the timeline can be removed (which I did). Since the last command given in the function is a gotoAndStop(), the stop takes care of itself.

I added three more buttons, to handle the reverse actions of the first three.

Notice that all the buttons are assigned the same handler function, and that inside the function, they can be identified by "event.target."

Like I said, the functions assigned on frame 1 remain active throughout the timeline. Maybe now you can begin to see how scripts work with the timeline.

One thing to be aware of is that you can't add a listener to an object that won't appear until a later frame. You'll get null object reference.

Maz

DaForce2000
05-16-2008, 03:18 AM
Maz,
Thanks for the file. Much neater that way.

However the setup I need will need the buttons to play forwards or backwards thru different frames depending on where the playhead is at.

Am I able to put the if function on each steps keyframe?? so the buttons behave different at each step. As I cant have 1 button for forwards and one for reverse.. the final file doesnt work that way.
For example..
Buttons, A, B, C, D, E
when you press a button it goes to point *whatever* lets make it point B, then from point B, the B button is disabled. as your already there.. and then press E, it then tweens from B to E.. then your at E then the B button would tween from E to B, the A button would tween from E to A..etc.. so each stop of the way the buttons need to act differently.
Which I assume can only be achieved with AS on each of those steps/points keyframes.

I realise the functions remain active throughout the timeline, all the other script there was for enabling/disabling buttons and changing they they do at each keyframe.

So I need to incorporate what you have shown in this file, with the button control similar to what i was using before. And it should all work out.

I like the playforwards command, using that and the playbackwards command is great. Just as long as it doesnt repeat itself when it gets to the end frame, and picks up on the AS of that frame.

For example, if say you have a button that playsbackwards from 25-15, and on frame 15 there is action script that says that same button then playsforwards from 30-65. That should be fine yeah?
And I would need to disabled the button during that tween using the enabled=false which i was using before.

Thanks mate!!

skelebunny
12-10-2008, 06:59 PM
Hey Everyone,

I've figured out how to remove the EventListeners for when you click on a button and your unable to click on another button until the current page is done loading. I just can't figure out how to disable the button that is equal to the current page. Basically if your on the home page you can't click the home button.

I know that this has been discussed in this thread but I'm new to actionscript and I'm trying to figure out how to do it within my code.

Anyone?

Thanks



import fl.transitions.Tween;
import fl.transitions.easing.*;
import fl.transitions.TweenEvent;

home_mc.addEventListener(MouseEvent.CLICK, onClick); // onClick Event Listeners.
trees_mc.addEventListener(MouseEvent.CLICK, onClick);
contact_mc.addEventListener(MouseEvent.CLICK, onClick);

home_mc.buttonMode = true; // Turning hand cursor on.
trees_mc.buttonMode = true;
contact_mc.buttonMode = true;

var home:pageHome = new pageHome(); // Creating instances of pageContent.
var trees:treesPage = new treesPage();
var contact:pageContact = new pageContact();

home_mc.mcTarget = home; // Creating variable properties linking them to instances of content.
trees_mc.mcTarget = trees;
contact_mc.mcTarget = contact;

var currentPage:MovieClip = home; // Variables.
var nextPage:MovieClip;

home.alpha = 0; // Setting the X and Y of the pageHome instance and adding it to the stage.
home.x = 400;
home.y = 322;
addChild(home);

var myTween:Tween = new Tween(home,"alpha",Strong.easeOut,0,1,1,true); // Fading home onto the stage.

function onClick(e:MouseEvent):void
{
home_mc.enabled = false; // Turns off the hand cursor for all your buttons.
trees_mc.enabled = false;
contact_mc.enabled = false;
home_mc.removeEventListener(MouseEvent.CLICK, onClick); // Removes Event Listeners for your buttons so as not interrupt your animation.
trees_mc.removeEventListener(MouseEvent.CLICK, onClick);
contact_mc.removeEventListener(MouseEvent.CLICK, onClick);
nextPage = e.currentTarget.mcTarget; // The nextPage variable is equal to the currenTarget of the function "onClick" and it's variable property mcTarget.
var offTween:Tween = new Tween(currentPage,"alpha",Strong.easeOut,1,0,1,true); // Animates out your current page.
offTween.addEventListener(TweenEvent.MOTION_FINISH , onTween); // Creates and Event Listener for your next animation on tween.
e.currentTarget.removeEventListener(MouseEvent.CLI CK, onClick);


}

function onTween(e:TweenEvent):void
{
removeChild(currentPage); // Removes the currentPage if and only the offTween has finished.
currentPage = nextPage; // currentPage = nextPage.
currentPage.alpha = 0; // Setting the current page's alpha to 0 so if can fade in.
currentPage.x = 400; //
currentPage.y = 322; //
addChild(currentPage); // Add's currentPage.
var tweenOn:Tween = new Tween(currentPage,"alpha",Strong.easeOut, 0,1,6, false); // Animates on your current page.
tweenOn.addEventListener(TweenEvent.MOTION_FINISH, enableAll); // When tweenOn is finished we create an Event Listener called enableAl.
}



function enableAll(e:TweenEvent):void
{
home_mc.addEventListener(MouseEvent.CLICK, onClick);
trees_mc.addEventListener(MouseEvent.CLICK, onClick);
contact_mc.addEventListener(MouseEvent.CLICK, onClick);
home_mc.enabled = true; // Turns on the hand cursor for all your buttons.
trees_mc.enabled = true;
contact_mc.enabled = true;
}

Mazoonist
12-13-2008, 03:12 AM
It's hard for me to tell from your code just exactly where you're having a problem.

But to answer your question of how to associate a button with a page, I guess there might be many different ways of doing this. I find using parallel arrays is a good approach, though. So in your case, you might have:

var buttonArray:Array = [home_mc, trees_mc, contact_mc];
var pagesArray:Array = [home, trees, contact];
In your click handler function, you can detect which button was pressed by comparing each array item in buttonArray to e.currentTarget. Then if you want some action to happen to the associated page, that might go something like this:
function onClick(e:MouseEvent):void {
for(var i:int = 0; i < buttonArray.length; i++) {
if(buttonArray[i] == e.currentTarget) {
//perform an action on the associated page:
pagesArray[i].visible = true;
}
}
}
The above is just an example. The actual action you're wanting to perform will vary from this, I'm sure.

Also, some might consider looping through an array like this to be too inefficient, although I haven't had any problems doing it and it makes sense to me. But you can also do it like this:
function onClick(e:MouseEvent):void {
var theIndex:int = buttonArray.indexOf(e.currentTarget);
pagesArray[theIndex].visible = true;
}
Hope that helps.

skelebunny
12-14-2008, 10:29 PM
Hey Mazzonist. Thanks for the reply. I went ahead and declared those arrays and included the below actionscript into my onClick function. I didn't see any changes. I'm not too familiar with arrays so I could very possibly be doing something wrong.


function onClick(e:MouseEvent):void {
for(var i:int = 0; i < buttonArray.length; i++) {
if(buttonArray[i] == e.currentTarget) {
//perform an action on the associated page:
pagesArray[i].enabled = false;
}


I tested it and everything remains the same. Any idea?

Thanks again.

Mazoonist
12-15-2008, 12:23 AM
I think you should put together a working model and upload it.