Can someone follow what doing, and show me how to do it correctly? I’m new with strings and arrays. Anything you can suggest would be appreciated.
GOAL
I want script to calling display objects to the stage, and the timer to move images up and down to appear like a scrolling numbers. I start getting sloppy, and mess up passing to Tweener.
THOUGHTS
– An explanation or strategy may be enough, “I’ve got pretty close on this one”
– There was confusion regarding the Containers and addChildren…looked like arrays
THE CODE “get as far as error with NumbersView and numbers undefined etc”
//-------------------------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]);
}
The methods were proved separately. “I got a earlier version of the
document going, but I need to work through this to understand it.”
SYMBOL PROPERTIES
CLASS ImageView
TWEENER
The “caurina” folder needs to be present
ROLLING NUMBERS “SUCCESS loading numbers and connecting to counter”
——————————————————————————————–
What I did for Debu’s example
Placed the movie clip object on stage with two dynamic text fields in it.
Note
Make sure the container is placed on stage, has the two text fileds in it, and everything is given a proper instance name. Also include the caurina folder.
seconds MovieClip symbol with instance name of seconds
firstDigit Dynamic text field with instance name of firstDigit, placed in seconds
secondDigit Dynamic text field with instance name of secondDigit, placed in seconds
Symbol
Un-tick ‘Export for ActionScript’
Use ‘Name, Class, and Instance’ correctly
I’ve implemented a very simple example of what I believe you’re trying to do. It only contains one digit, the seconds, and simply counts up to 9, then back to 0 and up to 9 again. Each time the Timer object I’ve created is fired (every 1000ms, or 1s) it runs a function which tweens in the new digit. I’ve pasted the code below, and commented each line; let me know if you don’t understand any of it.
All this code requires is a simple MovieClip object on the stage with two dynamic TextFields inside it; one placed exactly below the other. I’ve named the containing object ‘seconds’, the top-most TextField ‘firstDigit’, and the bottom TextField ‘secondDigit’. Re-create this inside a Flash document, save it (making sure carina is in the same folder), paste the code in on frame 1, and it should work fine. Edit: I created an image to illustrate how the objects should be structured inside your .fla:
Oh, and as for that expert who told you to quote yourself, he doesn’t sound like such an expert to me 😉 Anyway, hope it helps!