Comment puis-je remplir mes champs de texte correctement et afficher un seul chiffre?
chaînes de caractères et champs de texte, AS3
Description de
Chaque textfield reçoit une sous-chaîne. Cela ne limite pas sa saisie, car les champs de texte affichent des nombres supplémentaires. Voir l'illustration.
Ex A
//Tweening method 'could substitute code with Tweener'
import fl.transitions.Tween;
import fl.transitions.easing.*;
//Timer that will run a sec and repeat
var timer:Timer = new Timer(1000);
//Integer values
var count:int = +220000000;
var fcount:int = 0;
//Events and starting timer
timer.addEventListener(TimerEvent.TIMER, incrementCounter);
addEventListener(Event.ENTER_FRAME, checkOdometerPosition);
timer.start();
//Tween Variables
var smoothLoop:int = 0;
var originalYPosition:Number = 0;
var upwardYPosition:Number = -99;
//Formatting String
function formatCount(i:int):String {
var fraction:int = i % 100;
var whole:int = i/100;
return ("0000000" + whole).substr(-7, 7) + "." + (fraction < 10 ? "0" + fraction : fraction);
}
//First Digit 'trigger set by using var upwardPosition as a constant'
function checkOdometerPosition(event:Event):void{
if (seconds9.y <= upwardYPosition){
var toText:String = formatCount(fcount);
//seconds9.firstDigit.text = formatCount(fcount);
seconds9.firstDigit.text = toText.substr(9, 9);
seconds9.y = originalYPosition;
seconds8.firstDigit.text = toText.substr(8, 8);
seconds8.y = originalYPosition;
seconds7dec.firstDigit.text = toText.substr(7, 7);
seconds7dec.y = originalYPosition;
seconds6.firstDigit.text = toText.substr(6, 6);
seconds6.y = originalYPosition;
seconds5.firstDigit.text = toText.substr(5, 5);
seconds5.y = originalYPosition;
seconds5.firstDigit.text = toText.substr(4, 4);
seconds5.y = originalYPosition;
seconds3.firstDigit.text = toText.substr(3, 3);
seconds3.y = originalYPosition;
seconds2.firstDigit.text = toText.substr(2, 2);
seconds2.y = originalYPosition;
seconds1.firstDigit.text = toText.substr(1, 1);
seconds1.y = originalYPosition;
seconds1.firstDigit.text = toText.substr(1, 1);
seconds1.y = originalYPosition;
seconds0.firstDigit.text = toText.substr(0, 1);
seconds0.y = originalYPosition;
}
}
//Second Digit
function incrementCounter(event:TimerEvent):void{
count++;
fcount=int(count)
if (smoothLoop < 9){
smoothLoop++;
}
else {
smoothLoop = 0;
}
var lolly:String = formatCount(fcount-1);
//seconds9.secondDigit.text = formatCount(fcount);
seconds9.secondDigit.text = lolly.substr(9, 9);
var addTween9:Tween = new Tween(seconds9, "y", Strong.easeOut,0,-222, .7, true);
seconds8.secondDigit.text = lolly.substr(8, 8);
var addTween8:Tween = new Tween(seconds8, "y", Strong.easeOut,0,-222, .7, true);
seconds7dec.secondDigit.text = lolly.substr(7, 7);
var addTween7dec:Tween = new Tween(seconds7dec, "y", Strong.easeOut,0,-222, .7, true);
seconds6.secondDigit.text = lolly.substr(6, 6);
var addTween6:Tween = new Tween(seconds6, "y", Strong.easeOut,0,-222, .7, true);
seconds5.secondDigit.text = lolly.substr(5, 5);
var addTween5:Tween = new Tween(seconds5, "y", Strong.easeOut,0,-222, .7, true);
seconds4.secondDigit.text = lolly.substr(4, 4);
var addTween4:Tween = new Tween(seconds4, "y", Strong.easeOut,0,-222, .7, true);
seconds3.secondDigit.text = lolly.substr(3, 3);
var addTween3:Tween = new Tween(seconds3, "y", Strong.easeOut,0,-222, .7, true);
seconds2.secondDigit.text = lolly.substr(2, 2);
var addTween2:Tween = new Tween(seconds2, "y", Strong.easeOut,0,-222, .7, true);
seconds1.secondDigit.text = lolly.substr(1, 1);
var addTween1:Tween = new Tween(seconds1, "y", Strong.easeOut,0,-222, .7, true);
seconds0.secondDigit.text = lolly.substr(0, 1);
var addTween0:Tween = new Tween(seconds0, "y", Strong.easeOut,0,-222, .7, true);
}
Ex A a 10 objets de texte, chacune avec une paire de champs de texte. Il est complexe de déplacer que Ex B, car il a une animation Y et des paires de numéros . Les objets de texte sont animés pour créer un effet de défilement. Il se déplace verticalement, et a un numéro de plomb et un numéro de rattrapage contenu dans chaque symbole. Voir l'illustration pour plus de description.
alt text http://www.ashcraftband.com/myspace/videodnd/noob___.jpg alt text http://www.ashcraftband.com/myspace/videodnd/noob__.jpg
Les compteurs sont mis à 2,200,000.00, juste pour voir si les chiffres sont peuplant.
Ex B fonctionne très bien! par exemple seulement
//STRING SPLITTER COUNTER with nine individual text fields
//Timer settings
var delay:uint = 1000/100;
var repeat:uint = 0;
var timer:Timer;
timer = new Timer(delay,repeat);
timer.addEventListener(TimerEvent.TIMER, incrementCounter);
timer.start();
//Integer values
var count:int = 0;
var fcount:int = 0;
//Format Count
function formatCount(i:int):String {
var fraction:int = i % 100;
var whole:int = i/100;
return ("0000000" + whole).substr(-7, 7) + "." + (fraction < 10 ? "0" + fraction : fraction);
}
//Split strings off to individual text fields
function incrementCounter(event:TimerEvent) {
count++;
fcount=int(count+220000000)
var toText:String = formatCount(fcount);
mytext9.text = toText.substr(9, 9);
mytext8.text = toText.substr(8, 8);
mytext7dec.text = toText.substr(7, 7);
mytext6.text = toText.substr(6, 6);
mytext5.text = toText.substr(5, 5);
mytext4.text = toText.substr(4, 4);
mytext3.text = toText.substr(3, 3);
mytext2.text = toText.substr(2, 2);
mytext1.text = toText.substr(1, 1);
mytext0.text = toText.substr(0, 1);
}
@debu, Cela fera l'affaire. La sous-chaîne fonctionne comme vous l'avez décrite. Sans inclure les zéros, il le jetait. Le flip, la led ou l'odomètre devraient tous fonctionner de la même manière maintenant. Merci. –
@debu, j'ai eu un moment bête :) Ma rangée de chiffres du haut ne bougeait pas parce que le plafond était réglé avec originalYPosition. Je n'ai pas non plus trouvé le point positif avec le tweening, mais c'est prometteur. –