Welcome to the MacNN Forums.

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

You are here: MacNN Forums > Software - Troubleshooting and Discussion > Developer Center > Flash components: retrieving data!

Flash components: retrieving data!
Thread Tools
Forum Regular
Join Date: Jan 2002
Status: Offline
Reply With Quote
May 14, 2004, 11:07 AM
 
This has got to be really simple, but thus far I just can't figure it out. The situation is I have an Listbox component that becomes populated with items (in the Label) and prices (in the Data). All I want is to have a sum of all the Data values in the listbox in a dynamic text field underneath.

So using this code:
Code:
for (i=0;i<=_root.listNeeds.length;i++) { if (_root.listNeeds.getItemAt(i).data != undefined) { sumNeeds += _root.listNeeds.getItemAt(i).data; } }
successfully seems to get the number set in the 'data' array in the listbox object (according to a trace). But when I try to add them together, it constantly claims "NaN." I've tried wrapping the above expression in a Number.(), to no avail.

Please help before I punch a hole in my cinema display.
     
Mac Elite
Join Date: Mar 2002
Location: Clogland
Status: Offline
Reply With Quote
May 14, 2004, 11:38 AM
 
     
Dedicated MacNNer
Join Date: Feb 2001
Location: Manhattan
Status: Offline
Reply With Quote
May 16, 2004, 08:55 PM
 
how bout wrapping the data with parseInt() prior to adding it...

Code:
sumNeeds += parseInt(_root.listNeeds.getItemAt(i).data);
     
Mac Elite
Join Date: Dec 2001
Location: Atlanta, GA, USA
Status: Offline
Reply With Quote
May 17, 2004, 08:09 AM
 
Is that Flash code? If so, the language has come a long way since I used it (Back in the days of Flash 4).
Mac Pro 2x 2.66 GHz Dual core, Apple TV 160GB, two Windows XP PCs
     
Grizzled Veteran
Join Date: Jun 2001
Location: Melbourne, Australia
Status: Offline
Reply With Quote
May 17, 2004, 06:29 PM
 
Originally posted by Arkham_c:
Is that Flash code? If so, the language has come a long way since I used it (Back in the days of Flash 4).
Yeah, Actionscript is cool. On par with Javascript 1.4+ but without all the nasty errors if your script references non-existent objects.

The editor to get it in there, however, is utter crap. You can create actionscripts in BBEdit and #include them, but that means a lot of app-switching if you're doing some major work.
Computer thez nohhh...
     
Mac Elite
Join Date: Mar 2002
Location: Clogland
Status: Offline
Reply With Quote
May 18, 2004, 12:29 AM
 
Actionscript 2.0 (which was released with Flash MX 2004) is even cooler. You must define your variables, which lessens errors, speeds the processing up and enables code hints in the editor.

It's also pretty much OO as well, as in making and extending classes which incidently have to be include files.
     
Forum Regular
Join Date: Jan 2002
Status: Offline
Reply With Quote
May 18, 2004, 03:19 PM
 
Just to add some completion to the subject, and to more or less echo what skalie just mentioned, the reason it wasn't working was it needed to be typed as a number. So I ended up wrapping the expression in a Number(). This was my first stab in AS2.0, so I keep stumbling on the easy stuff.

So I've been reading all about OOP in Flash, which seems pretty cool. I tried to write a Class, but for what I needed it to do, it didn't end up working. I was hoping I could throw a bunch of variables and functions into the class, and then "instantiate" it into an object, but it seems functions in classes are considered constructors, so I clearly have more reading to do. Using regular functions turned out to do the trick anyway.

Anyone have a great example of where using a Class would be helpful?
     
Mac Elite
Join Date: Mar 2002
Location: Clogland
Status: Offline
Reply With Quote
May 18, 2004, 08:26 PM
 
Originally posted by frownyfrank:
Anyone have a great example of where using a Class would be helpful?
A Movie is a Class, as is a Button.

You can extend them, for example adding rollover affects to a Movie to make it act like a Button.

Which you may or may not think is usefull, but if you want to make a hell of a lot of Buttons that all lose a certain (adjustable) amount of Alpha on Mouseover or something, extending a Movie Class could be a quickish way of going about it.

That being said, in Flash there's always 20 different ways of achieving the same effect.
     
   
Thread Tools
Forum Links
Forum 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 On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Top
Privacy Policy
All times are GMT -5. The time now is 06:31 PM.
All contents of these forums © 1995-2011 MacNN. All rights reserved.
Branding + Design: www.gesamtbild.com
vBulletin v.3.8.7 © 2000-2011, Jelsoft Enterprises Ltd., Content Relevant URLs by vBSEO 3.3.2