A Flash Developer Resource Site

Results 1 to 6 of 6

Thread: [mx]A more eloquent way to code.

  1. #1
    Senior Member pup100's Avatar
    Join Date
    Oct 2004
    Location
    Close
    Posts
    575

    [mx]A more eloquent way to code.

    Hi,

    I have been working on a way to make a preloader for a number of clips being loaded into a main clip.

    I have got it to work with the following code (this is the relevant snippet from the main code which is included below as an attachment):

    code:
    _root.holdtext_mc.onEnterFrame = function() {
    moonAmount = Math.floor((ticking_array[0].getBytesLoaded()/1024));
    magAmount = Math.floor((ticking_array[1].getBytesLoaded()/1024));
    empAmount = Math.floor((ticking_array[2].getBytesLoaded()/1024));
    inAmount = (moonAmount+magAmount+empAmount);
    this.read_txt.text = inAmount;

    };



    This all works fine but I was after a more eloquent way of going about it & so tried:

    code:
    _root.holdtext_mc.onEnterFrame = function() {
    for (i in _root.ticking_array) {
    tot_array.push(Math.floor((_root.ticking_array[i].getBytesLoaded()/1024)));
    }
    for (i in _root.tot_array) {
    am += _root.tot_array[i];
    trace(am);
    }



    But this gives some really wild figures.

    I think I'm on the right track but am just getting the designation of the bytesLoaded code wrong

    Anyone any help please
    Last edited by pup100; 01-04-2008 at 08:38 AM.
    You will know everything when you know you never will.

  2. #2
    Registered User nunomira's Avatar
    Join Date
    May 2002
    Location
    portugal
    Posts
    7,003
    hi,

    Take a look at this simple example:
    code:

    var myArray = new Array(1, 2, 3, 4);
    var total = 0;
    for (n in myArray)
    {
    total += myArray[n];
    }
    trace(total); // 10


  3. #3
    Senior Member
    Join Date
    Feb 2005
    Posts
    1,834
    Are you creating the variable am to begin with? If you don't define a variable by doing am=0 then anything else will be am+=1 or undefined+=1 == undefined. Be sure to make am = 0 before trying to add to it.
    .

  4. #4
    Senior Member pup100's Avatar
    Join Date
    Oct 2004
    Location
    Close
    Posts
    575
    Thank you both for your input.

    Nunomira- Problem I have got is that all of this is wrapped up in an onEnterFrame event, so although I would say your code would work wrapping it in the event wacks the numbers out.

    This is where I'm at as of this morning.

    code:
    _root.holdtext_mc.onEnterFrame = function() {
    for (i in _root.ticking_array) {
    _root.tot_array.push(Math.floor((_root.ticking_arr ay[i].getBytesLoaded()/1024)));
    for (i in _root.tot_array) {
    am += _root.tot_array[i];

    }
    }

    You will know everything when you know you never will.

  5. #5
    Registered User nunomira's Avatar
    Join Date
    May 2002
    Location
    portugal
    Posts
    7,003
    Depending on what you want to do, initialize the variable (total, in my example), inside the onEnterFrame.
    code:

    var myArray = new Array(1, 2, 3, 4);
    this.onEnterFrame = function()
    {
    var total = 0;
    for (n in myArray)
    {
    total += myArray[n];
    }
    trace(total);// 10
    };



    Tip:don't use _root, use relative paths instead.

  6. #6
    Senior Member pup100's Avatar
    Join Date
    Oct 2004
    Location
    Close
    Posts
    575
    Sorry to take a while to get back to you on the nunomira, but no joy

    Latest post on it, shows where i'm at http://board.flashkit.com/board/show...28#post3815828

    Thanks any way for your input.
    You will know everything when you know you never will.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center