Simple effect but very difficult to make it

Hi,
I am a flash developer, but I just meet a very serious problem on my work. I need to develop a very simple flash that contain several input textboxes. But I need to play a short animation when the mouse is over any one of the textboxes.
How can I know the mouse is over a input textbox ??
Thank you for your help.
Catalas.

I’m a novice flash designer so I may be off the mark here, but it sounds to me like you should make the input box a button and have the “OVER” state load a movieclip.

That make sense? Leaving the rest of the button states empty…

Jay

Well you can’t create a button out of dynamic text so I recommend making it a movie clip and using…


_root.yourClip.onRollOver = function() {
	_root.yourAnimation.gotoAndPlay(1);
};

Add that into the frame, not on the movie clip.

yourClip = your movie clip with the textbox
yourAnimation = the animation you want played.

Hope this helps :slight_smile:

Actually MX has made it so that you can make dynamic text a button unlike the previous version, in Flash 5 this would have been impossible!

I tried making it a button, but it would just make the loaded text selectable.

Hmm, stupid me, does it work if you uncheck the selectable text box?

I was under the impression catalas was talking about “input textboxes”, as in a form.

I don’t know that you can nest a form input into a button, but it would seem so…

Anybody know about multiple rollovers using dynamic images??? I’m stuck…

Jay

Ah yes, he did say imput. I must have skipped over that. Sorry

It worked for me, I made an input box with a variable ‘input_text’ and turning it into a button and placed this code on the button, and make sure you button has a hit state:

**on(rollOver) {
    input_text = "HELLO!";
}**

Hi,
O…I have tried the method mentioned by dan4885, I made a input text box and convert it to a button and placed the code inside. It just have the properties of input textbox (the mouse cursor change to “I” when mouse over it) and it does not have the RollOver event. Can help me??
Catalas

it seems that if the text is selectable, it doesn’t register an over event.

of course since text boxes have _x, _y, _height, and _width properties, there’s nothing preventing us from writing our own hit detect function.

say your text box was _root.text1:


text1.onMouseMove = function(){
	var x = _root._xmouse - this._x;
	var y = _root._ymouse - this._y;
	if(x > 0 && x < this._width && y > 0 && y < this._height){
		this.text = "over";
	}else{
		this.text = "out";
	}
}

// since text boxes don't receive mouse events by default,
// we need to add them as a listener.
Mouse.addListener(text1);

Thx, this method is work.
But I wonder if there are lots of input textboxes and every textbox need to implement this function, it seems affect the overall performance since every input textbox capture the mouse move event and run that function.

Sorry, I’ve been gone for a couple of days… let me ask you this…

if you create some movie clips with alpha = 0 and place them behind the textboxes. Can’t you just do the rollover on the movie clip and have it update the text box?

Actually, this is a rhetorical question, cause I know you can.

:slight_smile:

Also, you can use hover captions, if that is what you’re trying to do…

iam -

that method has a few problems. if the clip is behind the text field, the over event is not registered. if the clip is in front of the text field, you can’t select the text field for editing.

cat -

are you having performance problems? flash shouldn’t have any trouble running this kind of a script continously, i’m sure there are more efficient scripts out there…

you might want to make the assignment more efficient if you have enough text boxes. something like this:


function textOverDetect(){
	var x = _root._xmouse - this._x;
	var y = _root._ymouse - this._y;
	if(x > 0 && x < this._width && y > 0 && y < this._height){
		this.text = "over";
	}else{
		this.text = "out";
	}
}

function initTextOverDetect(){
	var i,tb = [text0,text1,text2,...funkyText];
	for(i in tb){
		tb*.onEnterFrame = textOverDetect;
		Mouse.addListener(tb*);
	}
}

initTextOverDetect();

the array tb should contain complete paths to each text box. the above would work assuming the text boxes are on the same timeline as the function.

Supra… Well… it’s kind of a hack, but it does work. if your mc is behind the input box, but slightly larger, it will take the rollover effect. The fact that it is only slightly larger acts perfectly for this case. Your input box remains editable and you can’t enter the box without rolling over it’s border.

=)

yes, that’s true, but you get a roll out event when you’re actually over the text box, and you trigger another mouse over when exiting.

if you’re not using the roll out for anything, and don’t mind the extra roll over trigger, that will work just fine!

true… true… that’s why I said… it’s a hack!

I like your code, as always.

Yeah, listeners can be really useful. For a good read, try Robert Penner’s tutorial about them at ultrashock, it’s in the tutorial section and [SIZE=3]very[/SIZE] interesting.
And we should make this part of the Best of Kirupa.

pom :asian:

Wow, that tutorial is very intriguing. I will definitely check this out when I am in the mood to learn about listeners.