Zurück   Flashforum > Flash > ActionScript > ActionScript 1

Antwort
 
LinkBack Themen-Optionen Ansicht
Alt 19-05-2005, 18:32   #1 (permalink)
Neuer User
 
Benutzerbild von redbolt
 
Registriert seit: Jul 2003
Ort: Stuttgart
Beiträge: 118
Question fehler in for-schleife

Habe hier eine Schleife in der ich einigen Textfeldern beim erhalten und verlieren des Focus Eigenschaften übergebe.

ActionScript:
  1. function textfelder_prop(){ //Muss nochmals in jedem Frame aufgerufen werden.
  2.     for(i=0;i<textfeld.length;i++){
  3.         this[textfeld[i]].onSetFocus=function(null){
  4.             if(this.text=="---")this.text="";
  5.             this.textColor="0x013858";
  6.             //this.number=i+2;
  7.             hilfetext.gotoAndStop(i+2);
  8.         }
  9.         this[textfeld[i]].onKillFocus=function(null){
  10.             if(this.text=="")this.text="---";
  11.             this.textColor="0xFFFFFF";
  12.         }
  13.     }
  14. }

Alle Eigenschaften Funktionieren, nur egal welches Textfeld einen Fokus erhält springt hilfetext immer in Bild 12. Bei allen springt hilfetext in das Bild des Betrags textfeld.length+2.

Was mache ich falsch.
redbolt ist offline   Mit Zitat antworten
Alt 19-05-2005, 18:36   #2 (permalink)
mod_rewrite
 
Benutzerbild von sonar
 
Registriert seit: Feb 2003
Ort: München
Beiträge: 15.621
Das alte Lied vom i...
ActionScript:
  1. function textfelder_prop (){ //Muss nochmals in jedem Frame aufgerufen werden.
  2.        
  3.  for (var i=0; i < textfeld.length; i++) {
  4.  
  5. this["textfeld" + i].id = i;
  6.              
  7.   this["textfeld" + i].onSetFocus=function (){
  8.                         if (this.text == "---") this.text="";
  9.                         this.textColor = "0x013858";
  10.                         hilfetext.gotoAndStop (this.id + 2);
  11.                 };
  12.  
  13.                 this["textfeld" + i].onKillFocus=function (){
  14.                         if (this.text == "") this.text = "---";
  15.                         this.textColor = "0xFFFFFF";
  16.                 };
  17.         }
  18. }
__________________
RTFM
Wie man Fragen richtig stellt.

Achim Bindannmalweg

Money makes the world go round, fear makes it turn much faster.
(New Model Army)
sonar ist offline   Mit Zitat antworten
Alt 19-05-2005, 18:46   #3 (permalink)
Neuer User
 
Benutzerbild von redbolt
 
Registriert seit: Jul 2003
Ort: Stuttgart
Beiträge: 118
ne, so einfach dann doch nicht.

Sorry hätte wohl dazusagen sollen, dass textfeld ein array ist
in den Arrayfeldern stehen als String die Namen der Textfelder.
Ich kann also nicht textfeld+i verwenden.
redbolt ist offline   Mit Zitat antworten
Alt 19-05-2005, 19:04   #4 (permalink)
poke
 
Registriert seit: Dec 2002
Ort: Iserlohn [NRW]
Beiträge: 2.304
ActionScript:
  1. function textfelder_prop()
  2. { //Muss nochmals in jedem Frame aufgerufen werden.
  3. for( var i:Number = 0; i < textfeld.length; i++ )
  4. {
  5. this[ textfeld[i] ].id = i;
  6. this[ textfeld[i] ].onSetFocus=function()
  7. {
  8. if( this.text == '---' ) this.text = '';
  9.  
  10. this.textColor = '0x013858';
  11. hilfetext.gotoAndStop( this.id + 2 );
  12. }
  13. this[ textfeld[i] ].onKillFocus=function()
  14. {
  15. if( this.text == '') this.text = '---';
  16.  
  17. this.textColor = '0xFFFFFF';
  18. }
  19. }
  20. }

mit deiner Version versuchst du immer auf i zuzugreifen. Dieser Zurgriff findet allerdings erst nach der Definierung der Funktion statt. Zu diesem zeitpunkt ist i dann textfeld.length+2
pokepika ist offline   Mit Zitat antworten
Alt 19-05-2005, 19:27   #5 (permalink)
mod_rewrite
 
Benutzerbild von sonar
 
Registriert seit: Feb 2003
Ort: München
Beiträge: 15.621
@pokepika: wenn du's jetzt noch für MX tauglich machst, passt's...
__________________
RTFM
Wie man Fragen richtig stellt.

Achim Bindannmalweg

Money makes the world go round, fear makes it turn much faster.
(New Model Army)
sonar ist offline   Mit Zitat antworten
Alt 20-05-2005, 06:00   #6 (permalink)
poke
 
Registriert seit: Dec 2002
Ort: Iserlohn [NRW]
Beiträge: 2.304
mx? ähhm ^^

reicht doch so oder?
ActionScript:
  1. function textfelder_prop()
  2. { //Muss nochmals in jedem Frame aufgerufen werden.
  3. for( var i = 0; i < textfeld.length; i++ )
  4. {
  5. this[ textfeld[i] ].id = i;
  6. this[ textfeld[i] ].onSetFocus=function()
  7. {
  8. if( this.text == '---' ) this.text = '';
  9.  
  10. this.textColor = '0x013858';
  11. hilfetext.gotoAndStop( this.id + 2 );
  12. }
  13. this[ textfeld[i] ].onKillFocus=function()
  14. {
  15. if( this.text == '') this.text = '---';
  16.  
  17. this.textColor = '0xFFFFFF';
  18. }
  19. }
  20. }
pokepika ist offline   Mit Zitat antworten
Alt 20-05-2005, 12:13   #7 (permalink)
Neuer User
 
Benutzerbild von redbolt
 
Registriert seit: Jul 2003
Ort: Stuttgart
Beiträge: 118
danke leute,
jetzt funktionierts. habe einfach die id vor der onSetFocus-Funktion gesetzt.
redbolt ist offline   Mit Zitat antworten
Antwort

Lesezeichen

Themen-Optionen
Ansicht

Forumregeln
Es ist Ihnen nicht erlaubt, neue Themen zu verfassen.
Es ist Ihnen nicht erlaubt, auf Beiträge zu antworten.
Es ist Ihnen nicht erlaubt, Anhänge hochzuladen.
Es ist Ihnen nicht erlaubt, Ihre Beiträge zu bearbeiten.

BB-Code ist an.
Smileys sind an.
[IMG] Code ist an.
HTML-Code ist aus.
Trackbacks sind an
Pingbacks sind an
Refbacks sind an



Alle Zeitangaben in WEZ +1. Es ist jetzt 11:17 Uhr.

Domains, Webhosting & Vserver von Host Europe
Unterstützt das Flashforum!
Adobe User Group


Copyright ©1999 – 2012 Marc Thiele