Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Mouse event (OVER and CLICK) problem

Guest
Nov 19, 2008 Nov 19, 2008
Hi everyone.

I'n new to AS3 and it's been a HASSLE to figure out some simples things i used to solve easily on AS1 and AS2...

I have a BUTTON called BOTAO82 which when having a MOUSE OVER event, should show a simple TEXT on a specific location of the screen (something explaining where that button will take you to).
That button will have two events: MOUSE_OVER and MOUSE_CLICK.
The CLICK i got it right...OK.
The problem is the OVER. How can i SHOW the related TEXT when the mouse is over that button?

Here's what i put on the STAGE as code:

=============
botao82.addEventListener(MouseEvent.MOUSE_OVER, botao82over);
botao82.addEventListener(MouseEvent.CLICK, botao82click);

function botao82over(event: MouseEvent)
{
// don't know what to do here...
}
function botao82click(event: MouseEvent)
{
gotoAndPlay("video82");
}
===============

Any ideas, please?

PS.: The first thing i tried was putting the TEXT to show INSIDE the BUTTON configuration, which ended up making the AREA OF THE TEXT a button ITSELF! Gee whiz... terrible!

Thanks everyone! 😉
TOPICS
ActionScript
868
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Deleted User
Nov 19, 2008 Nov 19, 2008
So, just so we have everything CLEARED in our minds... here goes the FINAL working code:

------
txt82.visible = false;

botao82.addEventListener(MouseEvent.MOUSE_OVER, botao82over);
botao82.addEventListener(MouseEvent.MOUSE_OUT, botao82out);
botao82.addEventListener(MouseEvent.CLICK, botao82click);
function botao82over(event: MouseEvent)
{
txt82.visible = true;
}
function botao82out(event: MouseEvent)
{
txt82.visible = false;
}
function botao82click(event: MouseEvent)
{
gotoAndPlay("video82"...
Translate
Explorer ,
Nov 19, 2008 Nov 19, 2008
import flash.text.TextField;

var text : TextField = new TextField();
<<--- Add your placement and formatting code here.
You're going to want to check out the TextField and TextFormat documentation. TextField isn't an object you can just use right off the bat. It'll need some formatting.
<<--------
addChild(text);



function botao82over(event : MouseEvent)
{
You can either do it one of two ways either set the text to be what you want or set the text earlier and just control it via the visible state.
text.text = "";
text.visible = true;
}

either way you're probably going to want a MOUSE_OUT event listener to turn the text off.
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Nov 19, 2008 Nov 19, 2008
What would you have done with AS2 to solve this? The solution can't be that far off.
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Nov 19, 2008 Nov 19, 2008
Ok then... The turning ON and OFF of the VISIBILITY looks promising...
The thing IS: i already have all the texts FORMATTED.

I could make all of them OBJECTS, which are already positioned, and only ask to turn them ON and OFF.

Ok, i made one of the texts a GRAPHIC called "txt82".
And i inserted it on the MOUSE_OVER function.
==========
function botao82over(event: MouseEvent)
{
txt82.visible = true
// Have to DEFINE a variable for this, huh? how can i do this?
}
===========
Hope defining the variable solves this...
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Nov 19, 2008 Nov 19, 2008
NedWebs,

In AS1 all i did was put this code directly inside the button.
"menu0" didn't have the text and "menu1" had the text beside it.
Really easy...

on (rollOver)
{
gotoAndPlay("menu1");
}

on (rollOut)
{
gotoAndPlay("menu0");
}


Now in AS3 i had to add SO MUCH CODE in different places that if i put a duplicate of all the STAGE with a text and make every button's MOUSE_OVER point to that place, i'm gonna have a FIT... :D LOL
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Nov 19, 2008 Nov 19, 2008
You might have a fit... I know I did when I started to use AS3.... walking around mumbling and stuff... but it gets easier with practice.

Yeah, there's more code involved, but that was a choice someone at Adobe made and most of the OO folks think it's great. I still have my reservations, but that's life.

Here's an option as well... just have a text field that you write to... fill it for the mouseover (tField.text = "stuff") and empty it for the mouseout (tField.text = "") .

Regarding your second to last posting, I don't know what variable you need to define, so I can't answer that, but you define a variable the same way you should have been doing back in the AS2 days.

By the way, are you YELLING? I can hear just fine.
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Nov 19, 2008 Nov 19, 2008
Ned,

Sorry about the YELLING... i consider it more like marking out more important words... then, i think it would be better to just put 'em bold, then...
Oh well...

Ok, tField.text ... oh boy... ANOTHER thing to study... I never used that...
Seems to be getting more and more complicated.
As i understand it, using this command, i'll have to research how to format the text in another way than visually directly on the stage...

Oh my...
Is it really so hard to turn a text on or off?
Or maybe make it's instance become alpha=0 ?
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Nov 19, 2008 Nov 19, 2008
Hey guys!

I found this tutorial on the net:

http://www.flashvalley.com/fv_tutorials/mouse_events_in_actionscript_3.0/page2.php

But i still have difficulties in getting only what i need for the text to SHOW UP on the screen.

I'm an artist who used to program a loooooooong time ago...
So, i'm trying to get the quickest way of making this work.

Please, help, someone... 😞
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Nov 19, 2008 Nov 19, 2008
Ok......

I managed to ISOLATE the part i wanted... and i came up with THIS:

----
stop();

video1.txt1.visible = false;

video1.addEventListener(MouseEvent.MOUSE_OVER,showtxt1);
video1.addEventListener(MouseEvent.MOUSE_OUT,showtxt1);
video1.addEventListener(MouseEvent.CLICK,video1click);

function showtxt1(e:MouseEvent){
if(e.type == "mouseOut"){
e.currentTarget.txt1.visible = false;
}

if(e.type == "mouseOver"){
e.currentTarget.txt1.visible = true;
}
}
function video1click(e:MouseEvent){
gotoAndStop(2);
}
---

And it works very well!!!! YES!
The only problem IS:
the object has to be a MOVIECLIP, not a BUTTON...
Must create a conflict if set as a button... gonna test that now.
But anyway, i got it figured out, i think! Just have to throw this code into my other file and see what happens.

Thanks everyone!
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Nov 19, 2008 Nov 19, 2008
I was just gonna post almost exactly what you answered with. Nice job! You even figured out the MOVIECLIP vs (GRAPHIC) deal which I was also ready to tell you about. I had it copied and ready to paste in, but I found you got it working when I returned... cool!
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Nov 19, 2008 Nov 19, 2008
Hey Ned,

ANOTHER thing! Yey!

On the SETTINGS of flash, you have to go in action script 3.0 settings and mark "automaticaly declare stage instances"..
That way the txt.visible = true/false will work!!

Yey again!
Thanks!
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Nov 19, 2008 Nov 19, 2008
LATEST
So, just so we have everything CLEARED in our minds... here goes the FINAL working code:

------
txt82.visible = false;

botao82.addEventListener(MouseEvent.MOUSE_OVER, botao82over);
botao82.addEventListener(MouseEvent.MOUSE_OUT, botao82out);
botao82.addEventListener(MouseEvent.CLICK, botao82click);
function botao82over(event: MouseEvent)
{
txt82.visible = true;
}
function botao82out(event: MouseEvent)
{
txt82.visible = false;
}
function botao82click(event: MouseEvent)
{
gotoAndPlay("video82");
}

where txt82 and botao82 are MOVIECLIPS with those exact instance NAMES.

And voilá! That's it!
Not forgetting to mark the
"automatically declare stage instances"
on the settings for AS3 !
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines