有人可以关注做什么,并告诉我如何正确地做到这一点?我是字符串和数组的新手。任何你能建议的东西都会受到赞赏。
目标
我希望脚本将显示对象调用到舞台上,并且上下移动图像的计时器看起来像滚动数字。我开始变得草率,然后把它传给了Tweener。
THOUGHTS
- 解释或策略可能就足够了,“我已经非常接近这个了”
- 有关容器和addChildren的混淆......看起来像数组
代码“使用NumbersView和未定义的数字等错误”
//-------------------------IMPORT METHODS---------------------------------------
import flash.display.DisplayObject;
import flash.display.MovieClip;
import flash.utils.Dictionary;
import flash.events.Event;
import caurina.transitions.Tweener;
//-----------------------TIMER---------------------------------------
var timer:Timer = new Timer(1000);//
//var timer:Timer;
var count:int = 0;
var fcount:int = 0;
var _listItems:Array = new Array();
var previousNums:Array;
const numHeight:int = 120;
//var numbers:NumbersView;
timer.addEventListener(TimerEvent.TIMER, incrementCounter);
timer.start();
//-----------------------COUNTER-CONT-----------------------
function incrementCounter(event:TimerEvent) {
count++;
fcount=int(count*count/1000);//starts out slow... then speeds up
// mytext.text = formatCount(fcount);
NumbersView(1);
//}
//----------------------ZERO PLACE HOLDERS-----------------------
}
function formatCount(i:int):String {
var fraction:int = i % 100;
var whole:int = i / 100;
return ("000000000" + i).substr(-9, 9);
// return ("0000000" + whole).substr(-7, 7) + "." + (fraction < 10 ? "0" + fraction : fraction);
}
//
//----------------------DISPLAY for loop, integer to string "puts numbers on stage"
function NumbersView($n:int):void {
//function NumbersView()//
//{
_listItems = new Array();
previousNums = new Array();
var item:NumberImage;
var offset:int = _listItems.length;
//for (var i:int = 0; i < $n; i++)
for (var i:Number = 0; i < 9; i++)
{
item = new NumberImage();
//item.x = (i + offset) * 9;
//item.y = (i + offset) * 9;
item.x = i * item.width;
_listItems.push(item);
addChild(item);
}
//----------------------SPLIT STRING "pass to Tweener or some other method"---------------
//
function setTime($number:String):void {
var nums:Array = $number.split("");
for (var i:Number = 0; i < nums.length; i++) {
if (nums[i] == NumbersView[i]) continue;
Tweener.removeTweens(NumbersView[i]);
}
分别证明了这些方法。 “我有一个早期版本的 文件正在进行,但我需要通过这个来理解它。“
符号属性
CLASS ImageView
中间人
“caurina”文件夹需要存在
滚动数字“成功加载数字并连接到计数器”
----------------------------------------------- ---------------------------------------------
我为Debu的例子做了什么
将影片剪辑对象放置在舞台上,其中包含两个动态文本字段
注意
确保容器放在舞台上,其中包含两个文本文件,并为所有内容提供了正确的实例名称。还包括caurina文件夹。
秒实例名称为秒的MovieClip符号
firstDigit 实例名称为firstDigit的动态文本字段,以秒为单位
secondDigit 实例名称为secondDigit的动态文本字段,以秒为单位
符号
取消选中“Export for ActionScript”
正确使用“名称,类和实例”
答案 0 :(得分:0)
我已经实现了一个非常简单的例子,说明我认为你要做的事情。它只包含一个数字,即秒数,最多只计数9,然后再计数到0,最多再计9。每次我创建的Timer对象被触发(每1000毫秒或1秒),它就会运行一个补间新数字的函数。我已粘贴下面的代码,并评论每一行;如果你不理解任何一个,请告诉我。
import caurina.transitions.*;
//Create a timer that will run for 1 second, and repeat
var secondTimer:Timer = new Timer(1000);
//A counter for seconds
var secondsCount:int = 0;
//The original position of the rolling numbers object on the stage
var originalYPosition:Number = 0;
//The position of the rolling numbers object on stage when it's displaying its second digit
var upwardYPosition:Number = -127;
//The speed you want the odometer to roll at. As this is the seconds counter it needs to be less than 1
var rollSpeed:Number = 0.25; //seconds
//Start the timer
secondTimer.start();
//Add an event listener to fire each time it reaches its limit
secondTimer.addEventListener(TimerEvent.TIMER, updateOdometer);
//Add a generic update loop, to test for when the odometer has been moved to its 'up' position
addEventListener(Event.ENTER_FRAME, checkOdometerPosition);
function updateOdometer(event:TimerEvent):void
{
//When the timer fires, check if secondsCount is less than 9; if it is, increment secondsCount
if (secondsCount < 9)
{
secondsCount++;
}
else
{
//Otherwise set secondsCount to 0, so the odometer will loop from 9 back to 0
secondsCount = 0;
}
//Set the text inside seconds > secondDigit equal to the next digit it needs to display.
seconds.secondDigit.text = secondsCount.toString();
//Do the tween, so that the secondDigit changed above will become visible
Tweener.addTween(seconds, { y: upwardYPosition, time: rollSpeed, transition:"easeOutQuad" } );
}
//This function runs all the time, to check when the rolling object has moved upwards
function checkOdometerPosition(event:Event):void
{
//Do the check to see if it's in its upward position..
if (seconds.y <= upwardYPosition)
{
//If it is, make the first digit equal to the current second digit
seconds.firstDigit.text = secondsCount.toString();
//Then move the odometer back into its original position..
seconds.y = originalYPosition;
//This is so that the odometer is ready to be moved upwards again when the timer fires again.
}
}
所有这些代码需要的是舞台上的一个简单的MovieClip对象,里面有两个动态TextField;一个正好位于另一个之下。我将包含对象'seconds',最顶层的TextField'firstDigit'和底部的TextField'secondDigit'命名。在Flash文档中重新创建它,保存它(确保carina在同一个文件夹中),将代码粘贴到第1帧,它应该可以正常工作。 编辑:我创建了一个图像来说明如何在.fla中构建对象:
哦,至于那位告诉你引用自己的专家,他对我来说听起来不是这样的专家;)无论如何,希望它有所帮助!