?
Solved

Flash TextField Color on Focus

Posted on 2003-02-19
17
Medium Priority
?
1,343 Views
Last Modified: 2007-12-19
How can i change the color of TextField when it receives Focus and lost focus using Flash 5.
U can see www.macromedia.com site they have made it.
Thanks in advance
0
Comment
Question by:Gawai
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 6
  • 5
  • 3
  • +3
17 Comments
 

Expert Comment

by:akvalley
ID: 7981396
Here is what I use, adapted from a Colin Moock example:


//  Build an array of textfield names
editFields_array = [firstname_txt, lastname_txt, address1_txt, address2_txt, city_txt, state_txt, zip_txt];

//-------------------------
// TextField Method >> onSetFocus
//-------------------------
// ::: Set Focus callback function
// [~] Description - Set focus callback functions for text fields. These cause
// the textfields to highlight when focussed.
for (var i = 0; i<editFields_array.length; i++) {
     editFields_array[i].onSetFocus = handleFieldFocus;
}
//-------------------------
// TextField Method >> onKillFocus
//-------------------------
// ::: Kill Focus callback function
// [~] Description - Set killfocus callback functions for text fields.
// These remove textfield highlight when a field loses focus.
for (var i = 0; i<editFields_array.length; i++) {
     editFields_array[i].onKillFocus = handleFieldBlur;
}

//-------------------------
// Callback >> Field Focus
//-------------------------
//  
// ::: handleFieldFocus function
// [~] Description - Highlights a text field when it receives focus.
// [~] Parameters - None
function handleFieldFocus() {
     this.backgroundColor = 0xFFFFFF;
}
//-------------------------
// Callback >> Field Blur
//-------------------------
//  
// ::: handleFieldBlur function
// [~] Description - Removes highlight on a text field when it loses focus.
// [~] Parameters - None
function handleFieldBlur() {
     this.backgroundColor = 0xF3F3F3;
}
0
 

Expert Comment

by:Forbin
ID: 7982096
you could use the above method but create  a seperate movie with the textbox and let it have three frames; the first one would set the textbox to a blur color and stop.  The second and third frames would loop through each other, gradually changing the color until the desired color is reached.

You could use a variable like "isFocused" or something to test and see which color the textbox should be set to in the first frame, and to test to see if the color should be increased or decreased in the second and third frames.

If you didn't want to do this, you could create a movie that sits on top of the textbox (same size) that has two tweens -> start color(stop) to end color (stop), then back to start color(gotoAndStop(1)), then say onFocus tell the movie to play the necessary frames.

I'd say the first way is better and easier.
0
 

Expert Comment

by:Forbin
ID: 7982103
oh yeah the point of me writing that was b/c I noticed the macromedia.com one FADES from color to color, and I didn't know if that was the effect you were after.
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 6

Expert Comment

by:henryww
ID: 7983449
nah... forbin ...

akvalley's solution is nice & clean...
works great

there will be problem using a movieclip on a textbox .. u can't type!


btw, is the email not working???

0
 
LVL 5

Expert Comment

by:elhy
ID: 7986077
yeah, i agreen that akvalley's solution is the best. i think changing colors should avoid using mc with frames that contain diff color. its not flexible at all and may increase filesize.
0
 
LVL 20

Author Comment

by:Gawai
ID: 7986275
it doesn't work in flash 5 version
0
 
LVL 20

Author Comment

by:Gawai
ID: 7986276
it doesn't work in flash 5 version
0
 
LVL 6

Expert Comment

by:henryww
ID: 7986555
well ... not for 5 ... sorry only MX

with 5, u will have to use Forbin's method.

cheers
0
 

Expert Comment

by:Forbin
ID: 7987028
I wasn't talking about putting a movie over top (well I was in my second solution, but that will obviously not work).

I'm talking about creating a movie with the textbox inside it, have 3 frames and two layers, one layer just has the textbox, the other has actions.

The first one sets the textbox color based on an "isFocused" variable, the second and third frames loop through each other, changing the color gradually based on the "isFocused" variable, then jumping back to the first frame when the color change is finished.  I'm sure akvalley's solution is clean and easy but it also instantly changes the color if I'm not mistaken, I've never used MX so I don't know how that works, but I'm assuming setting the background color instantly changes it rather than fading into it.

I don't see why this wouldn't work, but then again, I've never used textboxes!  Just going on programming logic alone, it seems like a decent solution.  
0
 
LVL 6

Expert Comment

by:henryww
ID: 7988726
hey gawai, ur question is being answered here by all the experts...

gawai just post the msg again in Q_20515891.html and asking for help there ... :)

yes forbin... it works and it is a great idea to do the fading effect :)

but ... how to detect if the box get's the focus & lost focus (not rollOver nor rollOut)? this is what i can't figure out how to do with flash 5 ...

let's say u put a button on the textbox and when use click on the button and put the focus on the textbox and do the fading effect, like one of the question previous asked (the tooltip thing) ... i am not sure how it can be done in flash 5, but MX ... yes sure we can do exactly like the search box in macromedia ....

i have no idea
can u guys figure out how?
0
 
LVL 23

Accepted Solution

by:
Zeffer earned 50 total points
ID: 7990990
henryww..you could do it in 5 with a hotspot button and the Selection Object..targeting the variable name of the textfield..and the clip stopped on frame 1 could run say 10 frames for the colour fade..and stop back on 1

eg..

on(release){
Selection.setFocus("_root.myClip.myVar");
 _root.myClip.gotoAndPlay(2);
}

//that's set the focus and run the colour change

on(releaseOutside){
_root.myClip.gotoAndPlay(2);
}

//that'll run the colour change when the field loses focus

Z


0
 
LVL 6

Expert Comment

by:henryww
ID: 7998025
ok ... i see
i thought selection object is only for MX ...

thanks Zeffer

now here u go gawai
0
 

Expert Comment

by:Forbin
ID: 7998633
you don't need 10 frames, all you ever need is 2 frames and good scripting
0
 
LVL 20

Author Comment

by:Gawai
ID: 8007268
Thanks u all for every thing
Please visit http://www.macromedia.com and see is search engine, they have made this not with Flash MX but with flash 4 or 5 version. i m very much sure about it because i m regular visitor of this web site since 1998. Flash MX is the new version.
So ur help will be appreciated if u give me idea of creating such textField using flash 4 or 5
Thnaks
0
 
LVL 6

Expert Comment

by:henryww
ID: 8007607
i think if u analysis and understand all the things we had said here, u should be able to do that already...

give me sometime and i can come up with an example for u, however, i don't have flash 5 here, i can only avoid using any MX function and save the fla for 5,...

cheers
0
 

Expert Comment

by:Forbin
ID: 8007729
if you take my suggestion, add in what henryww said using Zeffer's method, and take some snippets from akvalley's code, you should be good to go!

:)
0
 
LVL 6

Expert Comment

by:henryww
ID: 8007785
yes ... sure ... with all the experts :)
& we sure make a phD - combined.
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

There are times in your Flash CS4 application when you want more than a simple pointer or a hand, and it's hard to find an ideal walk-through to tell you what to do.  I spent a few days recently learning my way around making custom cursors in Flash,…
I have found that much of my time doing support ends up being a constant repetition of the same steps to different people.  Early on I stated using web pages with Frequently Asked Questions (FAQs) to alleviate most of the burden.  Sometimes this jus…
The goal of the tutorial is to teach the user how to set there setting in Adobe Flash Media Live Encoder and YouTube for optimal video and audio quality.
The goal of the tutorial is to teach the user what frame rate is, how to control it and what effect it has on the video.
Suggested Courses

765 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question