Good day, I am extremely new to flash and am attempting (the impossible I think) to teach myself. I am trying to design an interaction for online learning (using AS3.0) where there are 4 characters. You can then click on each character in any order and little thought bubbles pop up with more information. I have managed to get it to work, however when you click the next character, the first character you clicked reverts back to the 'up' state. I used buttons to create this. So what I want to happen is to click on the first 'button', have it change from black (up state) to orange (down state), and when I click on the next 'button', for the first one to stay orange and not revert to black again.
No worries :)...
Yes, there is an easier way. I think you should do this with 1 frame. Make those info bubbles(Which should be MovieClips) invisible/visible when you click on the buttons. Now you could place all of these in an array, but since you are a beginner and there are only 4 items, there isn't much need. Place all of them on the stage at their right locations and give them instance names. Start from scratch with stop(); in the code. Next make a function like this:
What this function does is turn all bubbles invisible.
The next thing you should do is call this function like this:
Actionscript Code:
changeBubbles();
Now if you want a bubble to be visible from the start write this:
Actionscript Code:
nameOfBubble1.visible = true;
This would make bubble1 visible.
Now add mouse click listeners to every button and make the button functions look like this:
Actionscript Code:
function nameOfHandlerForButtonX(event:MouseEvent):void { changeBubbles(); nameOfBubbleX.visible = true; }
X should be the number of the button/bubble.
So what this will do is first turn all buttons invisible and then turn the button you want the user to see visible.
This should work, but if you still have any problems, please don't hesitate to ask.
Oh and for the down state of the buttons... I don't think you can do that with Button symbols, as they are pre-programmed for you with such properties. When the user releases the mouse they go to up/regular state. This could be solved by writing you own button class, but that requires a lot more Actionscript 3.0 knowledge, as well as OOP.
What I would recommend is that you make your buttons with MovieClip symbols.
Add event listeners for mouse over, mouse out, mouse down and mouse up and then use gotoAndStop() to change the frames. On mouse up you should use: gotoAndStop(frameYouWantItToStayOn). But, when you keep activating more buttons all the previous ones will stay that way, so you will have to use buttonNumberX.gotoAndStop(regularFrame) for every other button.
function buttonClicked(event:MouseEvent):void
{
gotoAndStop(2);
}
So now when you go back to the main timeline and you click on the first button, it changes colour and shows the relevant bubble. When you click on the next one, the first one stays orange and the next one also turns orange and shows the relevant bubble, which is exactly perfect!
My last question (on this scenario) would be how to do the scripting for mouse over so you can see the colour change when you hover over it?
Great that it worked ^^...
As for the mouse inside/outside testing...
You could use hitTestPoint(mouseX, mouseY, true) with an if... But for you I would recommend adding MouseEvent.MOUSE_OVER and MouseEvent.MOUSE_OUT listeners. MOUSE_OVER activates when your mouse goes inside the button and MOUSE_OUT activates when it goes outside.
Ok, I've done the script exactly as per your instructions, but it still doesn't stay orange after I've clicked it :-( I've added hand cursors though which are very cool :-)
Actionscript Code:
stop();
//Add Handcursor so it behaves like a button mybutton1.buttonMode = true; mybutton1.useHandCursor = true;
Oh, it's because you used gotoAndPlay. You should use gotoAndStop, since gotoAndPlay goes to a frame and plays the animation from there on. Sorry, my mistake in my earlier post.
Hiya, yes, that is exactly what I want it to do!! I've compared the scripting and it's exactly the same now. But one your's it works fine, and on mine when you roll over the button with your mouse, it turns orange and stays orange...it doesn't go black when you roll out again :-( I am pulling my hair out! The setup is the same as well, except mine are movieclips with instance names where you don't specify the names.....
Well, if you use code in an objects timeline then you shouldn't specify its instance name, since the code you write refers to all instances of that MovieClip. You could use an instance name in your code if for example you have other objects inside that MovieClip or if you want to refer to another object that's not in that MovieClip... Anyway, I am not sure what else could be wrong with your version... If you could upload it so that I can take a look?