views:

54

answers:

1

alt text

The code for the counter was easy to follow, but I'm stumbling through this next phase. Getting a counter display "images" instead of dynamic text.

One of my mentors gave me the code this way. I've got a working example, but I messed it up. Can someone explain how to put this together?

Documents
numbers.fla
NumberDocumentClass.as
NumbersView.as

Checked This
- run numbers.fla without doing anything "counter works fine, but no image sprites"
- class names "NumbersView,NumberDocumentClass"
- import classes, import NumbersView; import NumberDocumentClass;

attaching class definition to number_0.jpg in library
5000: The class 'NumberDocumentClass' must subclass 'flash.display.BitmapData' since it is linked to a library symbol of that type.

Runtime Error "after attaching NumbersView.as"
1046: Type was not found or was not a compile-time constant: TimerEvent.

alt text alt text

Other Issues "maybe other post" - string and array need setup "sort of understand"

numbers.fla

//"counts to a million with two decimal places"
import flash.events.TimerEvent.*;

var timer:Timer = new Timer(10); 
var count:int = 0; //start at -1 if you want the first decimal to be 0<    
var fcount:int = 0;   

timer.addEventListener(TimerEvent.TIMER, incrementCounter);    
timer.start();    

function incrementCounter(event:TimerEvent) {    
  count++;    
  fcount=int(count*count/10000);//starts out slow... then speeds up   
  mytext.text = formatCount(fcount);  
}  

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);   
}

NumberDocumentClass.as

package {
    import flash.display.Sprite;
    import flash.utils.Timer;
    import flash.events.TimerEvent;

    /**
     * ...
     * Brightest and Best!
     */
    public class NumberDocumentClass extends Sprite {

        private var timer:Timer = new Timer(10);
        private var count:int = 0;
        private var fcount:int = 0;
        private var numbers:NumbersView;

        public function NumberDocumentClass() {
            timer.addEventListener(TimerEvent.TIMER, incrementCounter);    
            timer.start();   
            numbers = new NumbersView();
            addChild(numbers);
        }

        function incrementCounter(event:TimerEvent) {    
            count++;    
            fcount=int(count*count/10000);//starts out slow... then speeds up   
            //mytext.text = formatCount(fcount);  
            numbers.setTime(formatCount(fcount));
        }  

        function formatCount(i:int):String {   
            //var fraction:int = i % 100;   
            //var whole:int = i / 100;   

            return ("000000000" + i).substr(-9, 9); 
        } 
    }
}

NumbersView.as

package  
{
    import flash.display.MovieClip;

    /**
     * ...
     * Brightest and Best!
     */
    public class NumbersView extends MovieClip
    {

        private var _listItems:Array = new Array();

        public function NumbersView() 
        {
            trace("POOP");
            var item:NumberImage;
            for (var i:Number = 0; i < 9; i++) {
                item = new NumberImage();
                addChild(item);
                item.x = i * item.width;
                _listItems.push(item);
            }

        }

alt text

+2  A: 

I posted the source.

http://shaneberry.net/numbers/

You should really take the time to start doing some reading. Though my help may have gotten you through these issues, you are not likely to get the same walkthrough type help on any other questions here.

Start with the basics, then work your way up. I certainly didn't learn all of the flash / actionscript I know over night.

There are a ton of online tutorials and really good books out there. Do some research.

NOW

When you say,

string and array need setup "sort of understand"

What do you mean? Are you referring to how I use an array in NumbersView? What "string" are you talking about?

sberry2A
Not a question really, just exploring strings and arrays. My questions seem lazy, but I'm trying to expose my own "ignorance" so I can fix it. The "problem solving skills" haven't kicked in yet, but they will. Where do I go next?
VideoDnd
The output seems to explain it.
VideoDnd