1 message in com.googlegroups.google-finance-apis[Google Finance APIs] storing quote.g...
FromSent OnAttachments
tyna...@gmail.comApr 6, 2009 10:57 am 
Actions with this message:
Paste this link in email or IM:
Paste this link in email or IM:
Atom feed for this thread
Paste this URL into your reader:
Subject:[Google Finance APIs] storing quote.getQuotes data after calling quote.addListenerActions...
From:tyna...@gmail.com (tyna@gmail.com)
Date:Apr 6, 2009 10:57:37 am
List:com.googlegroups.google-finance-apis

hell, i am trying to store data pulled from getQuotes in a variable for use after addListener is called, but some curious variable scope problems have arisen. It looks as though it is treating the variable as global outside of quote.AddListener() and a local inside. here is the code:

<?xml version="1.0" encoding="UTF-8" ?> <Module> <ModulePrefs title="hellofinance"> <Require feature="finance"/> </ModulePrefs> <Content type="html"> <![CDATA[

<script type="text/javascript">

var quote = new google.finance.Quote(); var last = "notaprice";

quote.getQuotes(["GOOG"]);

quote.addListener(function(data) { last = data[google.finance.LAST]; document.write(last); })

document.write(last);

</script> ]]> </Content> </Module>

when i load this in iGoogle, the output is "notaprice" then the last price for goog is printed on top of that. why is "notaprice" still stored in the variable last? feels like document.write(last) is being called before anything else? any help would be more than appreciated.