-1

I am wondering if it is possible to define several textfield/boxes as one variable? For example: I have five textFields, all with different names - "show1" & "show2" etc. Can I for instance define them all as one variable?

var key;
key = show1 && show2 ... etc.
key.visible = false;

Please help me. Thank you so much for answer.

J.Hage
  • 13
  • 5
  • 1
    No you cannot and not just in as3 but with any programming language. Put them in an array and loop through it. – BotMaster Apr 14 '16 at 15:00

1 Answers1

0

Sometimes in as3 or javascript or other programming language I store several variables inside just one variable using separators.

For example if you have your 5 textfields and want to put them inside only 1 variable. I would do this;

var key;
key = show1 + '|||' + show2 + '|||' + show3;

so there you will have all texts inside a variable separated by |||

to use that separated then you will have to split that var, for example:

array = key.split('|||');

I usually do that when I need to communicate an array like variable between platforms, AS3 to PHP through POST or GET, or ajax with PHP etc.

Alvaro Hernandorena
  • 610
  • 1
  • 5
  • 18
  • Alvaro, thank you so much... I have another question, this is "homework" for tomorrow.:: I am supposed to make a program where the user can, add stuff and remove it in case it is wrong... And then it is supposed to write out the smallest number in a textfield. – J.Hage Apr 14 '16 at 15:26
  • you need to store those variables and then edit them? do they need to be saved when you close and open? or just saved as long as you are in the app?. if you don't need to save for later then just work with variables and that's it. if you need the data to be saved for later you can use the sharedObject (http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/net/SharedObject.html) the shared object is fine for small amount of data, if you need to store a lot you also have SQLITE, but I think it is only for when you export for AIR from AS3. – Alvaro Hernandorena Apr 14 '16 at 15:32
  • This is the task (I really dont get it) : a) Create an application where the user can record data from 2008 to 2012. It shall be possible to remove or change the data for a year if they have registered the wrong number. Use data from the above table. b) Extend the application to calculate what year that had the fewest crimes when it came to drinking and driving and illegal speed combined. What year was this, will appear on screen. – J.Hage Apr 14 '16 at 15:34
  • You will need a part where the user enters the new data on text fields, with a button you save those values on an array, then you save that array inside a sharedObject. Then you need a part that read those arrays inside sharedObject and displays them on the screen. And finally you will need to add a feature in the display part where you program that if the record is from the last year you can edit it, if the user clicks edit , you take the values from that row in the sharedObject for edition, you write the text fields with those values and add a save changes button. – Alvaro Hernandorena Apr 14 '16 at 15:48
  • yes I understand that I need to that, but I dont get it "on the paper". I know what to do, but I dont got the skill to do it. If you understand?... – J.Hage Apr 14 '16 at 15:53
  • just google it up, search this "as3 save data into sharedObject" to make part 1, google "as3 show data from sharedObject" for part 2. – Alvaro Hernandorena Apr 14 '16 at 15:54
  • 1
    There seems to be no point in first creating a string to later split it into an array for this application. `var array:Array = [show1, show2];` will work just fine. @J.Hage: don't ask additional questions in comments, create new questions for them. – null Apr 14 '16 at 18:58