텍스트 필드를 올바르게 채우고 한 자리수를 표시하려면 어떻게해야합니까?
문자열과 텍스트 필드, AS3
설명
각 텍스트 필드는 문자열을 수신한다. 텍스트 필드에 여분의 숫자가 표시되기 때문에 입력 내용이 제한되지 않습니다. 그림을 참조하십시오.
예
//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);
}
예 텍스트 필드의 쌍 (10) 텍스트 오브젝트 각각을 갖는다. Y 애니메이션과 숫자 쌍이 있기 때문에 Ex B보다 이동 복잡합니다. 텍스트 객체는 스크롤 효과를 만들기 위해 애니메이션 처리됩니다. 수직으로 이동하며 각 기호에 포함 된 리드 번호와 캐치 업 번호가 있습니다. 자세한 설명은 그림을 참조하십시오.
alt text http://www.ashcraftband.com/myspace/videodnd/noob___.jpg alt text http://www.ashcraftband.com/myspace/videodnd/noob__.jpg
카운터는 숫자를 채우는 경우 바로보고, 2,200,000.00으로 설정됩니다.
Ex B 잘 작동합니다! 예에만
//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, 그렇게합니다. substr은 설명대로 작동합니다. 0을 포함하지 않으면, 그것은 그것을 버리고 있었다. 플립, 리드 또는 주행 거리계는 모두 동일한 방식으로 작동해야합니다. 감사. –
@debu, 나는 어리석은 순간을 보냈다 :) 천장이 originalYPosition으로 설정 되었기 때문에 맨 위 열의 숫자가 움직이지 않았다. 트위닝과 함께 달콤한 자리를 찾지 못했지만 약속을 보여줍니다. –