[haXe] Accessing FlashVars in haXe
Michael Pliskin
pl at tepkom.ru
Mon Sep 25 12:58:14 CEST 2006
Hello Keith,
FlashVars become fields in flash root movieclip, i.e. in your case
it will be
flash.Lib.current.strExternalData
to avoid compile errors/warnings, use
var value: String = untyped flash.Lib.current.strExternalData;
and then do whatever you like.
KH> I am compiling haXe code to Flash 8, and am wondering if/how it
KH> is possible to access FlashVars sent by the webbrowser. I couldn't
KH> find anything in the documentation/tutorials or references.
KH>
KH> Imagine the XHTML file to have something similar to this snippet:
KH> <object type="application/x-shockwave-flash"
KH> data="filename.swf?strExternalData=hello" width="400" height="150">
KH> <param name="movie" value="filename.swf ?strExternalData=hello" />
KH> <param name="allowScriptAccess" value="sameDomain" />
KH> <param name="quality" value="high" />
KH>
KH> <param name="FlashVars" value="strExternalData=hello" />
KH> </object>
KH>
KH> "Normally" (that is, with ActionScript 2.0 in the Macromedia
KH> Flash IDE), it is quite common for me to define a variable without
KH> giving it an initial value, and immediately check whether it is null.
KH> Personally, I hate this method, as it is totally non object
KH> oriented, and there is no way to get all the FlashVars sent (and
KH> certainly not as name/value pairs). However, at least it was
KH> possible given the name of the FlashVar you want to read.
KH>
KH> For example, the ActionScript (on the first frame of the
KH> timeline in the root) might have looked like:
KH> var strExternalData:String;
KH> if (strExternalData == null)
KH> strExternalData = 'Default Value';
KH> trace(strExternalData);
KH>
KH> And in the above case would output "hello".
KH>
KH> I can't seem to find any way of doing this in haXe, and if it
KH> isn't (yet?) possible, it would be useful, to be able to have
KH> access to something like flash.Lib.flashVars, which could be a
KH> Hash of type String. Or, the main function could have an argument
KH> called flashVars with this data in it?
KH>
KH> Then in the main function, (or assuming flash.Lib.flashVars is imported) one could simply say:
KH> var strData:String = flashVars.get('strExternalData');
KH> if (strData == null)
KH> strData = 'Default Value';
KH> trace(strData);
KH>
KH> In my opinion, this would be a much better replacement for the
KH> old method. If this is unlikely to happen, (or unnecessary because
KH> there are known workarounds,) perhaps someone would be kind enough
KH> to give me some pointers as to how I might achieve the same kind of thing?...
KH>
KH>
KH> Thanks for your time, and sorry for the long message ;)
KH> Keith Hall
KH>
--
Best regards,
Michael mailto:pl at tepkom.ru
More information about the Haxe
mailing list