 |
 |
Flash components: retrieving data!
|
 |
|
 |
|
Forum Regular
Join Date: Jan 2002
Status:
Offline
|
|
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
|
|
|
|
|
|
| |
|
|
|
 |
|
 |
|
Dedicated MacNNer
Join Date: Feb 2001
Location: Manhattan
Status:
Offline
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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.
|
|
|
| |
|
|
|
 |
 |
|
 |
|
|
|
|
|

|
|
 |
Forum Rules
|
 |
 |
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
|
HTML code is Off
|
|
|
|
|
|
 |
 |
 |
 |
|
 |
|