PDA

Volledige versie bekijken : [04P] createTextField()


Orion
%Europe/Berlin %739 %2005, 18:45
Wanneer ik een nieuw tekstveld aanmaak met de createTextField() functie dan kan ik er achteraf geen onSetFocus() functie op toepassen. Kan iemand zeggen hoe dat komt of bestaat er misschien een manier om dit wel gedaan te krijgen, want het zorgt voor een pak frustratie.

Groeten..

orion

Dauntless
%Europe/Berlin %746 %2005, 18:54
Rechtstreeks uit de help files:
Example
The following example creates two text fields called first_txt and second_txt. When you give focus to a text field, information about the text field with current focus and the text field that lost focus is displayed in the Output panel.

this.createTextField("first_txt", 1, 10, 10, 300, 20);
first_txt.border = true;
first_txt.type = "input";
this.createTextField("second_txt", 2, 10, 40, 300, 20);
second_txt.border = true;
second_txt.type = "input";
first_txt.onKillFocus = function(newFocus:Object) {
trace(this._name+" lost focus. New focus changed to: "+newFocus._name);
};
first_txt.onSetFocus = function(oldFocus:Object) {
trace(this._name+" gained focus. Old focus changed from: "+oldFocus._name);
}

Orion
%Europe/Berlin %754 %2005, 19:06
Het aanmaken van het tekstveld gebeurt in een functie en dan willen de onSetFocus en onKillFocus niet reageren.

get_account = function() {
_root.createTextField("user",_root.getNextHighestDept(),accounts._x,accounts._ y + accounts._height,100,100);
user.type = "input";
user.border = true;
user.html = true;
user.autoSize = true;
user.htmlText = "<font face='Tahoma' size='12' color='#999999'>Username</font>";
}

user.onSetFocus = function(){
trace("test");
if (user.htmlText == "Username") {
user.htmlText = "";
}
}
user.onKillFocus = function(){
if (user.htmlText == "") {
user.htmlText = "<font face='Tahoma' size='12' color='#999999'>Username</font>";
}
}

Dauntless
%Europe/Berlin %758 %2005, 19:12
Je roept die functie nergens op.... Maar dat zal je dan ergens anders doen I guess.

Je probleem is dat je textfield nog niet bestaat wanneer je er de onFocus handlers aan wilt toekennen.

function get_account() {
_root.createTextField("user", _root.getNextHighestDept(), accounts._x, accounts._y+accounts._height, 100, 100);
user.type = "input";
user.border = true;
user.html = true;
user.autoSize = true;
user.htmlText = "<font face='Tahoma' size='12' color='#999999'>Username</font>";
setFocusHandlers()
};
function setFocusHandlers() {
user.onSetFocus = function() {
trace("test");
if (user.htmlText == "Username") {
user.htmlText = "";
}
};
user.onKillFocus = function() {
if (user.htmlText == "") {
user.htmlText = "<font face='Tahoma' size='12' color='#999999'>Username</font>";
}
};
}
get_account();

Orion
%Europe/Berlin %770 %2005, 19:28
inderdaad, dat was het probleem en ik wist niet dat het zo kon opgelost worden, bedankt !