A Flash Developer Resource Site

Results 1 to 4 of 4

Thread: Math addition from List Component

  1. #1
    Junior Member
    Join Date
    May 2008
    Posts
    6

    Math addition from List Component

    Hi, a problem for the moment that I cannot solve by my self or find the solotion on the web.

    So I will try this cool forum instead.

    I am currently working with an upload script for flash, using flash as front ended and php as base script for the upload. Have created a single file upload script but now heading to create/modify mutiupload script

    I started from this code as a template.
    http://www.codeproject.com/KB/aspnet/FlashUpload.aspx
    I found it really good and working.

    I have added this time a list component where user can see what files
    she has added and to be uploaded.
    Code:
      for(var i:Number = 0; i < list.length; i++) {
      fileRef = list[i];
      totalBytes += fileRef.size;
      totalBytesCount = fileRef.size;
    
      fileBox.text += fileRef.name + '\n';
      fileBox.vPosition = status_txt.maxVPosition;
      fileBox.addItem({label:count++ +". "+ fileRef.name +" ("+ GetSizeType(totalBytesCount) + ") \n",data:fileRef.size});
    
      Fcount++;
      TotalSize.text = "Total size: " + GetSizeType(totalBytes) + "\n";
      TotalFile.text = "Total Files: " + (Fcount) + "\n";
      
      SpaceCaculation = CurrentSizeLimit - totalBytes;
      FileSIzeLimit.text = "Total Available Space: " + GetSizeType(SpaceCaculation) + "\n";
      }
    fileBox is list component name. As you see I have added file name, file size
    and in the datafield I have added the file size in bytes

    fileBox.addItem({label:count++ +". "+ fileRef.name +" ("+ GetSizeType(totalBytesCount) + ") \n",data:fileRef.size});

    GetSizeType is a function that just converts the size to diferent types
    of data, kb,mb,gb.

    The problem is calculating space/file size. I have allready succsseded with some of the problem

    SpaceCaculation = CurrentSizeLimit - totalBytes;
    FileSIzeLimit.text = "Total Available Space: " + GetSizeType(SpaceCaculation) + "\n";

    THe code calculate how much space I have remaining after I have added
    the files. CurrentSizeLimit is just a varialbe containing number.
    CurrentSizeLimit = 839000;

    THe real problem is when a user deletes a single item in the list, I wondering
    how I can update current space after a file has been remove. I can get the current file size from
    Code:
    totalBytesCount = fileRef.size; FileSizeC = totalBytesCount;
    List
    ------------------------------------------------------
    file name (size:converted) // Hidden data (size:bytes)
    testing.text (33kb) // (390252)
    testing2.text (34kb) // (41252)
    testing2.text (35kb) // (42252)
    ------------------------------------------------------

    Hope you guys understood me? If you dont ask and I will try to explain better. Thanks in advance.

  2. #2
    Junior Member
    Join Date
    May 2008
    Posts
    6

    :p

    It seems I wasnt understand. Will try my best to explain.

    I have an array with file size that contains
    bytes.

    Code:
    // Declaratin of the object
    var fileRef:FileReference = new FileReference();
    var fileRefList:FileReferenceList = new FileReferenceList();
    
    // More to declare
    var list:Array = fileRefList.fileList;
    var fileRef:FileReference;
    
    // This code extracts the file size (bytes) in the List component
    // When selecting mutiple items it counts them automatic, result is 
    // item1+item2+item3 and so on.
    // 50+50+20+50 = 170
    totalBytes += fileRef.size;
    
    // This doesnt count them, just displaying current file size. 
    totalBytesCount = fileRef.size;
    
    // Looping thrue all the items and counts them. 
    // 1+1+1+1+1 = 6
    for(var i:Number = 0; i < list.length; i++) {
    }
    As you see counter works 50%. I have added a delet button where a user can delete one file at the time depending on selection.

    Problem is how do I do to display right amount of left space when a user removes one item or more from the list component

    Below is the delete function

    Code:
     if(fileBox.selectedIndex != undefined){
    
     // This delete the item from the List component
     // On the stage the list is called fileBox
     fileBox.removeItemAt(fileBox.selectedIndex);
    
     // Display what file has been deleted by extracting it from OnSelect even,   scroll down for that function
     status_txt.text += selectedLabelString + "has been removed from the list"+"\n";
    
     progressBar.label = "File has been removed from the list";
     status_txt.vPosition = status_txt.maxVPosition;


    Code:
    //......Bblääuueehh
    var cbL:Object = new Object();
    
    
    // OnChange function
    // When selected file is printed
     cbL.change = function(event_obj:Object) { 
    
    // Yep.. 
     selectedDataString = event_obj.target.selectedItem.data;
     selectedLabelString = event_obj.target.selectedItem.label;
     selectedIndexString = event_obj.target.selectedItem.index;
    
     
    // Activating Deletebutton on selecting an item
     DeleteBtn.enabled = true;
     
     };
    The file size is 900kb, and when you are adding file the script
    subtract from 900 depending how many and how big the are.

    Example:
    Adding Cool.txt (50kb)
    900-50=850
    adding AnotherDoc.txt (20kb)
    850-20=830
    That function works greate

    Removing Cool.txt (50kb)
    830+50 = 880 <error dont know how to do it here>
    Removing AnotherDoc.txt (20kb)
    880+20 = 900 (it shall be back to normal) Not above or less.

    Please give me som hint or somthing? I am really stuck?.

  3. #3
    Junior Member
    Join Date
    May 2008
    Posts
    6

    HMm

    Okay, working on it now but..:P, I am forgetting one thing, hope you guys can see it?

    Code:
    //File size limit. 800kb something
    CurrentSizeLimit = 839000;
    
    // Math current limit - amount of added data
    // 800-x(kb)
    SpaceCaculation = CurrentSizeLimit - totalBytes;
    
    // Math again but this time I take the filesize limit minus the result
    // from the files were added
    
    // 800-760
     Test = CurrentSizeLimit - (CurrentSizeLimit - SpaceCaculation);
    // Then trying with 760+x files that are removed
     Test2 += Test+VarSizeSingle;
     trace(GetSizeType(Test2));
    
    This is the trace result, it doesnt count every item, just one of them
    758.29KB
    773.54KB
    773.54KB
    773.54KB
    773.54KB
    773.54KB
    5 files deleted. Just counting one of them.:S

  4. #4
    Junior Member
    Join Date
    May 2008
    Posts
    6

    Done :)

    Well lads, I have solved it. For ppl who followed my process the answer is easy.

    Code:
      Test += selectedDataString;
      Fcount += -1;
      totalBytes+= -selectedDataString;
      
      FileSIzeLimit.text = "Total Available Space: " + GetSizeType(Test) + "\n";
      TotalFile.text = "Total Files: " + (Fcount) + "\n";
      TotalSize.text = "Total size: " + GetSizeType(totalBytes) + "\n";

    I used selectedDataString from
    Code:
    // OnChange function
    // When selected file is printed
     cbL.change = function(event_obj:Object) {  
     selectedDataString = event_obj.target.selectedItem.data;
     selectedLabelString = event_obj.target.selectedItem.label;
     selectedIndexString = event_obj.target.selectedItem.index;
    
     
    // Activating Deletebutton on selecting an item
     DeleteBtn.enabled = true;
     
     };
    to extract current selected and deleted item, then simple math as I showed above in this thread.

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