|
#1
|
|||
|
|||
|
Hi All, I've a Little Problem About Linking The Paragraph Object With ListBox, So This My Idea, When a User gonna Choose A Number In The ListBox, The Content Of The Paragraph Object Must Change, Ex: " Number 1 From The Listbox Must Bring Me The Text Number 1 And So On "
ScreenShot :
|
|
#2
|
||||
|
||||
|
This is pretty simple. You'll get good at these little functions...
First, let's get the content you wish to display. It's always best to work off of databases and variables (this makes editing the content easier, while making your code faster and smaller in size). Using Notepad, create a text document that as these 4 lines of text in it: Text 1 Text 2 Text 3 Text 4 Make sure there are only four lines (that the last line isn't present as a 5th blank line or something). Save this file as Test.txt (or whatever name you wish). Now, on the "page load" code area, use the TextFile.ReadToTable function to read this document to a table called "MyTable". This will make it so that as the page loads, it reads your text document and creates a table filled with all of your text. In this case (although you won't see it), the table would be something like this MyTable = {"Text 1", "Text 2", "Text 3", "Text 4"}. Now your program has a list of all the text you might want to display at any given moment. The next step is to tie this text in with your list box...
__________________
"White-colla-AMS-gangsta."
|
|
#3
|
||||
|
||||
|
This is the code to do so...
CurrentNumber = 0; -- This just creates a counting system which we'll use to display in the listbox MyTableCount = Table.Count(MyTable); -- This command counts how many messages you have in your "MyTable" table and stores that number in the new variable "MyTableCount" while (MyTableCount > 0) do -- This command says "as long as there's a message left in the "MyTable" table that hasn't been checked, do this..." CurrentNumber = (CurrentNumber + 1); -- This is the counter in action. The first time this run, the string "CurrentNumber" will become 1 ("0" + "1" = "1"), the next time it will become 2 ("1" + "1" = "2") and so on... ListBox.AddItem("YourListBoxName", "Display text "..CurrentNumber, MyTable[CurrentNumber]); -- This command says "insert the contents of "MyTable" into the listbox called "YourListBoxName" so they match up MyTableCount = Table.Count(MyTable); -- This is very important! As with all "while loops", if you don't update the status, it will lock up in an endless loop end -- End the while loop with this command Now your list box has in the text area (which is shown to the user) the text "Display text 1", "Display text 2", etc. In the data area (which is not shown to the user), you have your messages from the MyTable table. They're just sitting there waiting to be called upon. Next, we'll set up how to call upon those messages and display them in the paragraph object...
__________________
"White-colla-AMS-gangsta."
|
|
#4
|
||||
|
||||
|
In the "on select" code area of your list box, your going to add a couple of lines of code so that when you click on the correct item in the list, it sends that item's "invisible" data (in this case the correct message) to the paragraph object. To do so, we just need to break it down step by step:
SelectedItem = ListBox.GetSelected("YourListBoxName"); -- This tells the computer which item the user selected and stores the info into a table called "SelectedItem" (this is a table, not a string) SelectedItemData = ListBox.GetItemData("YourListBoxName", SelectedItem[1]); -- This tells the computer to get the data at the selected item (SelectedItem[1]) and place that info in a string called "SelectedItemData" Paragraph.SetText("YourListBoxName", SelectedItemData); -- This tells the computer to replace whatever is in the paragraph object with the contents of the string called "SelectedItemData" (your message) That's it! The cool part about all of this is that simply by adding a new line of text into your text document (it doesn't matter what it is), it updates everything including the text displayed next to the item in your list box. It's completely dynamic.
__________________
"White-colla-AMS-gangsta."
|
|
#5
|
||||
|
||||
|
In case I messed up any of the code or skipped over a task by accident, other users should be able to help you. The key here is to break down your task (any task) into small commands that utilize the power of AMS's drag and drop "Action Wizard". As you get better at it, you'll be able to create smarter, dynamic functions that minimize your interaction with the code if you choose to edit it later on. I'm sure, in fact, that there are others on this forum that would have a smaller, faster solution than the one I offered you, but that's the fun of AMS7, right? Building your project the way YOU want it... not some other guy (like me).
__________________
"White-colla-AMS-gangsta."
|
|
#6
|
||||
|
||||
|
Hi,
As Protocol mentioned, there are many ways to do it. I'm attaching an example (AMS7), where I linked ListBox and Paragraph object and Text Files. Note: >> The source of Paragraph text comes from 3 Text Files located in the Docs folder. >> The source of File Names and Data in the ListBox are taken from the files using String.SplitPath and then dynamically added to ListBox using For..Do loop. Please check scripts in the: 1. Page OnShow 2. ListBox OnSelect I hope this simple example is useful.
__________________
Newbie Examples ------> AMS 7.5 : amstudio.azman.info ----> AMS 6 & 5: www.azman.info/ams/ ----> Twitter: www.twitter.com/azmanar/ |
|
#7
|
||||
|
||||
|
Hi,
Protocol did mentioned the use of TABLES (or arrays). It is very useful to control the text in the LISTBOX. This is a much better than ripping the name of the files (which sometimes is not pretty ). The attached example ( AMS7 ) uses a hardcoded table ( or array ) for the ListBox Text and Data. Look at the simple scripts in: 1. Page OnShow ( changed slightly but still uses For...Do loop ) 2. ListBox OnSelect ( unchanged )
__________________
Newbie Examples ------> AMS 7.5 : amstudio.azman.info ----> AMS 6 & 5: www.azman.info/ams/ ----> Twitter: www.twitter.com/azmanar/ |
|
#8
|
||||
|
||||
|
ListBox linking to RTF Object
Hi,
This is another example using the Tables method as above but loads text to a RichText Object instead of a Paragraph Object. Check the scripts in: 1. Page OnShow ( changed file extension only ) 2. ListBox OnSelect ( changed : gets RTF content from its file and loads it into the RTF Object ) Note: To wrap Text in RTF Display ( no scrolling ), unclick the Horizontal and Vertical Scroll Bars in the RTF properties.
__________________
Newbie Examples ------> AMS 7.5 : amstudio.azman.info ----> AMS 6 & 5: www.azman.info/ams/ ----> Twitter: www.twitter.com/azmanar/ Last edited by azmanar; 11-20-2007 at 11:19 AM. |
![]() |
«
Previous Thread
|
Next Thread
»
| Thread Tools | |
| Display Modes | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Help with listbox and paragraph text | airwv | AutoPlay Media Studio 6.0 | 3 | 06-07-2007 08:49 AM |
| Load column records into input object (with multiline enabled) or paragraph object. | sside | AutoPlay Media Studio 5.0 | 4 | 10-06-2004 01:40 PM |
| Example: Using the ListBox object | Ted Sullivan | AutoPlay Media Studio 5.0 Examples | 0 | 05-07-2004 01:24 PM |
| INFO: Difference between the Media Player Object and the AVI Object | Support | AutoPlay Media Studio 4.0 Examples | 0 | 10-29-2002 03:15 PM |
| HOWTO: Make a Media Player Object Go Full Screen | Support | AutoPlay Media Studio 4.0 Examples | 0 | 10-23-2002 12:23 PM |
All times are GMT -6. The time now is 11:52 PM.








Linear Mode

