MovieClip, counter almost working AS3
Posted
by VideoDnd
on Stack Overflow
See other posts from Stack Overflow
or by VideoDnd
Published on 2010-03-10T20:26:45Z
Indexed on
2010/03/11
5:13 UTC
Read the original article
Hit count: 351
flash
|actionscript-3
How do I get my counter to work? This was over my director's head. Please include explanation, and feel free to comment.
CONFUSION: I'm confused about the MovieClip container in as3. public class NumbersView extends MovieClip, so that seems to be a container. That may not be the problem, but that's where I got lost.
CODE http://videodnd.weebly.com/
The working version of this code is fantastic. My
code bellow is an attempt at revising it. The source
has been adapted from various smart people. It's a work in progress
LIBRARY OBJECT
'vertical number column'
Name: mc-NumberImage
Class: NumberImage
OUTPUT ERRORS 'When I uncomment the code"
1023: Incompatible override. NumbersView...
1021: Duplicate function definition. NumbersView...
//NUMBER DOCUMENT CLASS
//IMPORT
import flash.display.Sprite;
import flash.events.Event;
import flash.utils.Timer;
import flash.events.TimerEvent;
import flash.display.DisplayObject;
import flash.display.MovieClip;
import flash.utils.Dictionary;
import caurina.transitions.Tweener;
//COUNTER
var timer:Timer = new Timer(1000);
var count:int = 0;
var fcount:int = 0;
timer.addEventListener(TimerEvent.TIMER, incrementCounter);
timer.start();
function incrementCounter(event:TimerEvent) {
count++;
fcount=int(count*count/1000);
}
function formatCount(i:int):String {
var fraction:int = i % 100;
var whole:int = i / 100;
return ("000000000" + i).substr(-9, 9);
}
//------------------------------------------------------------------------
//PROBLEM AREA
function enterFrameHandler(e:Event):void
{
// numbers.setTime(formatCount(fcount));
}
var _listItems:Array = new Array();
var previousNums:Array;
const numHeight:int = 120;
var NumbersView:Sprite = new Sprite();
//var numbers:NumbersView = new NumbersView;
//NUMBERSVIEW
// function NumbersView($n:int):void {
_listItems = new Array();
previousNums = new Array();
var item:NumberImage;
var offset:int = _listItems.length;
for (var i:Number = 0; i < 9; i++) {
item = new NumberImage();
// }//<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
//------------------------------------------------------------------------
//PUSH ARRAY
addChild(item);
item.x = i * item.width;
_listItems.push(item);
}
//TWEENER 'Y SCROLLING'
function setTime($number:String):void {
var nums:Array = $number.split("");
for (var i:Number = 0; i < nums.length; i++) {
if (nums[i] == previousNums[i]) continue;
Tweener.removeTweens(_listItems[i]);
var newY:int = int(nums[i]) * -numHeight;
if (_listItems[i].y < 0) _listItems[i].y = numHeight;
Tweener.addTween(_listItems[i], { y:newY, time:3 } );
}
previousNums = nums;
}
D E S C R I P T I O N
COUNTER: formatCount needs to get passed to Tweener
STAGE: for loop, sets up children to be added to the stage NumbersView becomes item, item array adds children to stage
TWEENER: advances the vertical number column every time the count fires adds and removes
WHY
- Learning
- Benifit in simplifying the classes and putting it in one FLA
© Stack Overflow or respective owner