Home Tutorials Forums Articles Blogs Movies Library Employment Press

Go Back   ActionScript.org Forums > Extensions and Plugins > Components

Reply
 
Thread Tools Rating: Thread Rating: 5 votes, 5.00 average. Display Modes
Old 05-07-2003, 01:53 PM   #1
lecasn5
Registered User
 
Join Date: May 2003
Location: Lisboa
Posts: 38
Default Database simulated with arrays on a cd-rom

Hi there

I'm trying to make a presentation where people can search information by typing a number (ex: 102425) in a input text box and then click on a search button to go to a specified frame where the needed information is displayed. I could do that by using the if command, but the problem is that I have more than 4000 items and I'm not very eager to make 4000 lines of if commands. I suspect I have to use arrays and loops but I don't know how. Can anybody help me?

Thanks

Eduardo
lecasn5 is offline   Reply With Quote
Old 05-07-2003, 02:46 PM   #2
retrotron
thinking is design
 
retrotron's Avatar
 
Join Date: Apr 2003
Location: UK
Posts: 1,292
Default

4000 items shouldn't be too slow, especially if its in a standalone on a cdrom.

If you're using MX, I'd put the information in a RecordSet. You can write a loop to build that RecordSet (see example below).

Once you have a RecordSet full of your items, you can write a function which will "query" the RecordSet (it will use a loop to walk through each item and check for the number you're looking for). An array might be a tiny bit faster, but it'd be much easier with a RecordSet (which is nothing but an array anyways).

Here's a sample of how this would work. I first build a RecordSet, then I query that RecordSet for the information, displaying the result:
ActionScript Code:
// include the NetServices code so you can use the RecordSet object #include "NetServices.as" var allItems = new RecordSet(["itemID","itemName"]) for (var i=0; i < 5; i++) {     var itemToAdd = {itemID: i, itemName: "item_" + i};     allItems.addItem(itemToAdd); }  // end for loop function queryItems(x) {     // x: the value to search for     for (var i=0; i < allItems.getLength(); i++) { // loop through all items         var thisRecord = allItems.getItemAt(i);         if (thisRecord.itemID == x) {             return thisRecord;         } // end if statement     } // end looping through all items } // end queryItems() var result = queryItems(3); trace("Item number: " + result.itemID + " is " + result.itemName);
As you can see, this uses a loop to put some information into a RecordSet (the manner for building this RecordSet can be modified to suit your database. Let me know if you want some more info on building your particular RecordSet). Then the "queryItems()" function searches that RecordSet for the matching item. When it finds it, it stops looping and returns the record. This can easily be modified for the possibility that a search might return more than one record.

The nice element to doing it this way is you can have your "database" as a text file on the cd, load it with LoadVars, then put the information into a RecordSet which can be "queried" in the manner above.

retrotron

Last edited by retrotron; 05-07-2003 at 02:49 PM.
retrotron is offline   Reply With Quote
Old 05-07-2003, 08:32 PM   #3
lecasn5
Registered User
 
Join Date: May 2003
Location: Lisboa
Posts: 38
Default

Hi

I don't have the slightest idea of what a Recordset is, so I couldn't understand the code at all. I also have already solved the problem with arrays and a while loop. The only problem is that whenever I have to change the product number of the items (because a product might be discontinued) I have to be very careful to keep the arrays exactly related. Here's the code:

enter_btn.onRelease = function() {
productnumber = new Array(123, 124, 125);
items = new Array("pl 101", "pl 102", "pl 103");
i = 0;
while (productnumber[i] != input && i<productnumber.length) {
i++;
}
if (productnumber[i] == input) {
output = items[i];
} else {
output = "no matches found.";
}
};

Input and output is the var for a input text box and dinamic text box respectevily.
But I was very interested on that misterious (I couldn't find it it in the Flash help) recordset because you mentioned that we could have a kind of database in a txt file on the user computer (no need for server side). That would be very handy whenever I needed to make changes on the products.
lecasn5 is offline   Reply With Quote
Old 05-07-2003, 08:43 PM   #4
retrotron
thinking is design
 
retrotron's Avatar
 
Join Date: Apr 2003
Location: UK
Posts: 1,292
Default

Yeah, your solution does pretty much the same thing as mine. It works.

The RecordSet object is a very nice way to "simulate" a database (in the manner I mentioned in my first post) when you don't have one.

The RecordSet object is a new object built for Flash Remoting. Download the FlashRemoting Components from macromedia's site, run the install program, and then you're ready to go. The install program will install a file that's pure actionscript called "NetServices.as" in the proper macromedia directory on your computer. Then you can include this file with the following as the first line of code in your .fla:
Code:
"#include "NetServices.as"
(no semicolon on the end, and give it a full blank line underneath it before you start typing any code again, otherwise it will throw an error). Once the NetServices.as file is in your .fla, you can work with RecordSets.

Since NetServices.as was released only later with Flash Remoting, it doesn't appear in Flash Help (too bad, it's a very useful object). However, here is the documentation on the RecordSet object:

http://livedocs.macromedia.com/frdoc...a6.jsp#1170158

If you like, we can keep this thread going and work through how to use the RecordSet object (and maybe even use a textfile with it).
retrotron is offline   Reply With Quote
Old 05-07-2003, 08:50 PM   #5
lecasn5
Registered User
 
Join Date: May 2003
Location: Lisboa
Posts: 38
Default

Yes, I'm very interested in going on with the thread but I've got the impression that you are talking about a Flash projector that as to rely on a server ( you mentioned downloading FlashRemoting Components) and I want it to work local, on the user's computer. Am I right?
lecasn5 is offline   Reply With Quote
Old 05-07-2003, 09:01 PM   #6
retrotron
thinking is design
 
retrotron's Avatar
 
Join Date: Apr 2003
Location: UK
Posts: 1,292
Default

Yeah, local, from a text file. Flash Remoting is built for working with a server, but the RecordSet object that comes with Flash Remoting is also a great tool for use without a server, especially if you're reading large numbers of organized records from a text file (when, for example, you are running the file from a cd and don't have a database or server running).
retrotron is offline   Reply With Quote
Old 05-07-2003, 09:12 PM   #7
lecasn5
Registered User
 
Join Date: May 2003
Location: Lisboa
Posts: 38
Default

That's just what I wanted to listen (read)! I'm going to download the flash remoting and take a look at it. I'll be right back
lecasn5 is offline   Reply With Quote
Old 05-07-2003, 09:55 PM   #8
lecasn5
Registered User
 
Join Date: May 2003
Location: Lisboa
Posts: 38
Default

just downloaded it. But I can't find out help on how to relate the code with a txt file. Is there any recommended file extension for the text file? Does the code need to have some line calling the text file?
lecasn5 is offline   Reply With Quote
Old 05-09-2003, 05:24 PM   #9
retrotron
thinking is design
 
retrotron's Avatar
 
Join Date: Apr 2003
Location: UK
Posts: 1,292
Default

Hi lecasn5

Sorry I'm so delayed in answering, I was out of town for a few.

I'm not sure if there's any help out there regarding how to integrate Flash Remoting with a textfile (since technically you don't need Flash Remoting to work with a text file), but I can show you how. However, if you find any helps out there, let me know.

Just to be safe, let's test to be sure you have the Flash Remoting Components installed. Open up a blank .fla and insert this code into the first frame:
ActionScript Code:
#include "RecordSet.as" // create a new RecordSet object var myRecords = new RecordSet(); // test whether the object was successfully created trace(typeof myRecords);
The code first includes a file called "RecordSet.as" (this contains the code for RecordSets). The second line creates a new RecordSet object, and the third line tests whether it was created successfully.

Test the file. If the output window says "object", then the Flash Remoting Components have been installed and you're ready to go. If it says "undefined", then something's gone horribly, horribly wrong. Anytime you want to use a RecordSet, you must include this file in your code (just for kicks, remove the first line of code and run the file again).

Before we get too far along, let me ask you a question: how much do you know about object oriented programming?

retrotron
retrotron is offline   Reply With Quote
Old 05-10-2003, 02:06 PM   #10
lecasn5
Registered User
 
Join Date: May 2003
Location: Lisboa
Posts: 38
Default

Yes, it is installed.

Well, I was afraid you'd ask me that because I don't have much experience in object oriented programming, in fact I don't have much experience in programming. The first an only contact I had with programming was with AS and VBscipt. I know that this threads are supposed to be a place where people share mutual knowledge, so, and to be completely honest, i must tell you that if we move on with this thread I'm almost certain that I will be the only one getting something out of it because I don't have the knowledge for you to learn something from me. For this reason I will understand if you're not willing to keep this thread going.
lecasn5 is offline   Reply With Quote
Reply


Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump


All times are GMT. The time now is 11:49 PM.

///
Follow actionscriptorg on Twitter

 


Powered by vBulletin® Version 3.8.5
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
Ad Management plugin by RedTyger
Copyright 2000-2013 ActionScript.org. All Rights Reserved.
Your use of this site is subject to our Privacy Policy and Terms of Use.