Home Tutorials Forums Articles Blogs Movies Library Employment Press
Old 08-12-2009, 03:51 PM   #1
ranxbar
Registered User
 
Join Date: Jul 2009
Posts: 11
Angry Syntax Issues!

How can I combine a String inside a command that requires addressing to a position on an array?!

for instance:
//Accessing directly:
// i is int.
var toolsID:String=e.result.DocumentElement.sol_tools[i].ID;

//using string Value (w/o array):
var keyIndexValue:String= this[strTest].dataProvider[keyIndexPos/2].key.toString();

BUT(!) when i try to combine - I receive different errors:
//example:
var toolsID:String=e.result.DocumentElement.(this[ANYSTRING])[i].ID;

Suggestions?

------
"and then god allowed all syntax!"
ranxbar is offline   Reply With Quote
Old 08-12-2009, 08:10 PM   #2
wvxvw
Holosuit User
 
wvxvw's Avatar
 
Join Date: Oct 2006
Location: Tel Aviv
Posts: 4,301
Send a message via ICQ to wvxvw
Default

1. You really should cast e.result to something (I assume this must be an event you're getting from the WebService or similar class). But if not, then it looks even more weird:
- if DocumentElement is a property (not a name of XML node), then it should start with the lowercase.
- cast types whenever you use untyped access, i.e. if this[strTest] is meant to point to the object of type List, then do:
ActionScript Code:
((this[strTest] as List).dataProvider[keyIndexPos / 2] as XML).key.toString();
This works faster, makes your code at least somewhat readable, and let's you enjoy autocompletion.

Another thing to consider:
the scope inside the filter operator defaults to the currently processed node. So, if you use untyped access there, the compiler cannot forecast what variable are you going to refer inside the filter, so, if you do:
myXMLList.(this["someProperty"]);
the interpreter will look for "someProperty" node in the list's children, not in the function or class scope. And as even if you try to look for a child, which name's isn't in the XMLList you will get an XMLList as the result, the interpreter doesn't even try to look for your variable in another scope.

Bottom line:
- don't use untyped access.
- don't write "macaroni-style" code.
- cheers!
__________________
The .NET open source editor for Flash and web developers
*This would be my contribution to the project*
couchsurfing if you need it
wvxvw is offline   Reply With Quote
Old 08-13-2009, 08:24 AM   #3
ranxbar
Registered User
 
Join Date: Jul 2009
Posts: 11
Red face Hmmpf...

Well, I sure am a rookie player when it comes to writing code.
I wasn't even aware of the idea casing an event to (?) something... :-/

The fact is the webservice sends an XML structured response, and I get it from the webservice (result=functionName(event))
then - I try to fetch the xml-structured-data, by:

e.result.DocumentElement.tableName[recordNumber].fieldName (as string).

All I want is to place strings (variants) instead of writing the table and field names manually...

Thank you for replying, but since I'm so new to it, I understood only some parts of your explanation...
ranxbar is offline   Reply With Quote
Old 08-13-2009, 10:03 AM   #4
wvxvw
Holosuit User
 
wvxvw's Avatar
 
Join Date: Oct 2006
Location: Tel Aviv
Posts: 4,301
Send a message via ICQ to wvxvw
Default

You don't cast event, well, unless you have typed it to Event and in fact it was, say, a MouseEvent, and you need some specific MouseEvent properties. But, event.target is typed to Object, where a more precies type would be an IEventDispatcher... But, usually, you'd know even more preciese type of the target, like Button, WebService etc. The problem with event's target being an Object is that Object is a dynamic class, which means you can put whatever property on it and the compiler will not complain. However, once you run the untyped code, you actually get a strongly typed object as the terget, so, if it doesn't happen to have a property you wanted to access, you'll get a runtime error. This isn't good neither time-wise (you'll spend more time debugging such thing), nor performance wise (property access is different for typed and untyped objects, untyped access is slow).
__________________
The .NET open source editor for Flash and web developers
*This would be my contribution to the project*
couchsurfing if you need it
wvxvw is offline   Reply With Quote
Old 08-13-2009, 03:23 PM   #5
ranxbar
Registered User
 
Join Date: Jul 2009
Posts: 11
Lightbulb last request...

Hoping this isn't too odd - are you into (paid) private lessons?


P L E A S E?
(toothy smile attached)


I'm in TA, too. And all I need to know is how to send\receive data from a webservice (written in ASP) - (...by this moment I wrote a WS which reads data from an access file, sends it to Flex, and gets params - and it works!)

I need to sharpen my skills, a bit.

PLEASE
PLEASE
PLEASE
I'm a quick learner, too!
ranxbar is offline   Reply With Quote
Old 08-13-2009, 03:31 PM   #6
wvxvw
Holosuit User
 
wvxvw's Avatar
 
Join Date: Oct 2006
Location: Tel Aviv
Posts: 4,301
Send a message via ICQ to wvxvw
Default

Hey, I cannot really promise to give lessons, I'm not really sure I have a proper qualification, neither enough time to do that in any way properly / systematically but, whenever you feel like - you're welcome to visit / beer / coffee If you need my contacts, PM me.
__________________
The .NET open source editor for Flash and web developers
*This would be my contribution to the project*
couchsurfing if you need it
wvxvw 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 On
HTML code is Off

Forum Jump


All times are GMT. The time now is 09:29 AM.

///
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.