A Flash Developer Resource Site

Page 1 of 3 123 LastLast
Results 1 to 20 of 47

Thread: KM and Databases? CSV, mdb...

  1. #1
    Senior Member
    Join Date
    Mar 2006
    Posts
    191

    KM and Databases? CSV, mdb...

    Is there a possibility to integrate a lot of Textfiles with pictures...?
    All Data are available in a Datasheet (Access or a csv File)

    It would save a lot of time...

    Thanks all for help

  2. #2
    Senior Member
    Join Date
    Dec 2002
    Location
    Netherlands
    Posts
    1,632
    Access mdb files aren't possible without a server side language since they are binary files. CSV files can be read using the LoadVars class. Maybe you can be a bit more specific about what you are trying to accomplish.

  3. #3
    Senior Member
    Join Date
    Mar 2006
    Posts
    191
    Thanks...now
    I have in my Database many Products... with Prices, Infos and many Picturepaths...
    I have from these Products a csv File!

    Can I load a Field (from my csv file) in a Listbox to select and then link to a page?

    Example:
    Product A with 10 Fields (Price, Info...)
    Product B with 10 Fields (Price, Info...)
    Product C with 10 Fields (Price, Info...)

    KM should now import these Products (Infolist to click...) in a Listbox named Products
    The Listbox should select Product A and link to the Main-Infopage with these 10 Fields (Price, Picture, Infotext....
    We have many many Products...that means a lot of work....

    Is that possible?

  4. #4
    KoolMoves Moderator blanius's Avatar
    Join Date
    Jul 2001
    Location
    Atlanta GA
    Posts
    5,244
    Should be possible. Personally I'd still use serverside PHP to process the csv into a variables structure that KM could load.

    Show example of actual data.

  5. #5
    Senior Member
    Join Date
    Dec 2002
    Location
    Netherlands
    Posts
    1,632
    It's possible but how easy it will be depends on the complexity of the database.

    When you use the LoadVars class, it's onData event is triggered as soon as the file is read and passes the entire file as one big string. That means you'll have to do the field conversion yourself. Normally you'll first use the String.split function to split it on \n (line feed). After that you have an array where each item contains a record. Then you split each record into fields. If the delimiter is always "," it's no problem. If it sometimes is , and sometimes "," it becomes more difficult because if you would split on , you would also split a string that contains a , as part of the string and not as a field separator.

    How many records does your database contain ?
    If it's very large it might take the flash player a little time to process the data.

  6. #6
    Senior Member
    Join Date
    Mar 2006
    Posts
    191
    Thanks all...
    Germany 7:30 in the morning...KM is running...

    My csv List shows some fields like:
    Nr;Name;Artikelnummer;Kommentare;Beschreibung;
    There are 300-500 entries...

    Could you send me an example...? LoadVars class...? Difficult to understand ( Germany..) If it is to difficult, it would help me, if there is a possiblity to load data
    from 1 field in a listbox. Then I would to the rest yourself

    Bye
    Uwe
    P.S. My server can run csv Files and php...
    Last edited by Uwe S.; 04-06-2006 at 01:44 AM.

  7. #7
    Senior Member
    Join Date
    Dec 2002
    Location
    Netherlands
    Posts
    1,632
    Quote Originally Posted by Uwe S.
    Nr;Name;Artikelnummer;Kommentare;Beschreibung;
    It seems like you are using ; as a field delimiter.
    Here's an example
    Code:
    lv = new LoadVars(); // create a loadVars object
    
    lv.onData = function(src){ // set the onData function
     
     records = src.split('\n'); // create the record array
     for (var i = 0; i < records.length; i++){
      fields = records[i].split(';'); // split record into field array using ; as a field delimiter
      records[i] = {label:fields[0], value:fields[2]}; // replace a record with a label and value for the listbox
     }
     _root.listbox1.setItems(records); // set the listbox items
    
    }
    
    lv.load('myData.csv'); // load the CSV file
    In the example I'm using the first and third field as label and value for the listbox. Of course you can use other fields. If the csv file starts with a line that shows the field names you have to start at var i = 1; to skip the first line.

  8. #8
    Senior Member
    Join Date
    Mar 2006
    Posts
    191
    wow...Thanks so much,

    I will try it today...
    That means, I drag a Listbox ...but where exactly must I place this code?
    At Frame action?

    Uwe


    Uwe

  9. #9
    Senior Member
    Join Date
    Dec 2002
    Location
    Netherlands
    Posts
    1,632
    Quote Originally Posted by Uwe S.
    but where exactly must I place this code?
    At Frame action?
    Yes, you attach the code to a frame where the listbox exists.

    You will also have to set the onChange handler of the listbox to do something when the selection changes. You can do that using the gui's onChange parameter or integrate it into the code example.

  10. #10
    KoolMoves Moderator blanius's Avatar
    Join Date
    Jul 2001
    Location
    Atlanta GA
    Posts
    5,244
    Wilbert won't he need to add src= to the begining of the csv file?

  11. #11
    Senior Member
    Join Date
    Mar 2006
    Posts
    191
    Ok ...I understand
    I will try it....thanks...again
    I posted today another big problem with images (Links...)
    I would be very grateful, if you could help me! I can not fix it...

  12. #12
    Senior Member
    Join Date
    Dec 2002
    Location
    Netherlands
    Posts
    1,632
    Quote Originally Posted by blanius
    Wilbert won't he need to add src= to the begining of the csv file?
    No, that would be if you use the onLoad event. The onData event proceeds that. When you set an onData event you can process any entire file that's not binary encoded. That's what makes it so powerful

  13. #13
    KoolMoves Moderator blanius's Avatar
    Join Date
    Jul 2001
    Location
    Atlanta GA
    Posts
    5,244
    WOW I didn't realize this... This is significant to me...... Gotta go test some things.
    You are such a great resource here. Thank you.

  14. #14
    Senior Member
    Join Date
    Mar 2006
    Posts
    191
    Hi Bret an Wilbert,

    i have tried it but there is an error:

    My csvFile named myData.csv in in the same Folder..

    These are my DATA...

    Nr;Name;Artikelnummer;Kommentare;
    17424;Abschleppdienst;336;-;
    17425;PC;336;-;Infos

    I have changed this Line:
    records[i] = {label:Nr[0], value:Name[1]}//

    Nothing happens...

  15. #15
    Senior Member
    Join Date
    Dec 2002
    Location
    Netherlands
    Posts
    1,632
    Quote Originally Posted by Uwe S.
    records[i] = {label:Nr[0], value:Name[1]}
    You should't have changed it like that since there are no arrays named Nr or Name. If you want to use the first two fields, try it like this
    Code:
    lv = new LoadVars();
    
    lv.onData = function(src){
     
     records = src.split('\n');
     for (var i = 1; i < records.length; i++){
      fields = records[i].split(';');
      records[i] = {label:fields[0], value:fields[1]};
     }
     _root.listbox1.setItems(records);
    
    }
    
    lv.load('myData.csv'); // load the CSV file

  16. #16
    up to my .as in code Chris_Seahorn's Avatar
    Join Date
    Dec 2004
    Posts
    4,389
    You are such a great resource here.
    One wonders you aren't a mod here Wilbert? You are probobly the most adept at using the program other than Bob. Was it offered and turned down?

  17. #17
    Senior Member
    Join Date
    Mar 2006
    Posts
    191
    Everyone can use it but I have problems...
    1. Drag my Listbox (Listbox1)
    2. Edit Frame Action with this code above...
    3. MyData.csv is there...

    But nothing happens!

  18. #18
    Senior Member
    Join Date
    Dec 2002
    Location
    Netherlands
    Posts
    1,632
    Uwe, Can you post a csv with the structure you are using without information that's important to you, It should be something small but without the fun or csv file I can't tell you what it is.

    Chris, Bret and Bob do a great job moderating. Being a mod isn't my desire. It takes a lot of time since one has to read all posts and posting in english still takes me extra time since it isn't my native language.

  19. #19
    Senior Member
    Join Date
    Mar 2006
    Posts
    191

    CSV File...

    Hi Wilbert,

    all here are great and do their best!
    We have to translate...and it is sometimes realy hard...
    I included a Standard *.csv File for you
    This file is working with other applications very well.
    I can import it without problems.

    Could it be on the header:
    something like this

    "Produkt-ID";"Bezeichnung";"Preis";"

    thank you so much...
    It is not possible to upload *.csv (rename the file...to: wilbert.csv)
    Attached Files Attached Files

  20. #20
    KoolMoves Moderator blanius's Avatar
    Join Date
    Jul 2001
    Location
    Atlanta GA
    Posts
    5,244
    It's working you just need to understand what Wilbert has done in his code and go from there: I'll add comments
    code:

    //create a loadVars Object
    lv = new LoadVars();

    //set what to do when it has loaded it's data
    lv.onData = function(src){//src is the a "pointer" to the data

    records = src.split('\n');//This splits the text at each new line and puts it into an array called records
    //So for example your records[0] would contain the first line of the text file
    for (var i = 1; i < records.length; i++){//Now loop through the array and split it each again at each ;
    fields = records[i].split(';');
    now fields[0] will contain the first item in the first line and fields[1] will contain the second item
    records[i] = {label:fields[0], value:fields[1]};//Here he's reusing the records array and putting in the label and value pairs you need
    }
    _root.listbox1.setItems(records);//Set the label and Value using the array

    }

    lv.load('myData.csv'); // load the CSV file



    What he didn't show you was something to show that the values are there

    add
    code:

    listbox1.onChange=function(){
    _root.txt1.text=this.getValue()
    }

    and when you select an item in the list box it will show value in a text box called txt1

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