开发者

Instruction works outside of a function but not inside on ActionScript 2 Flash

开发者 https://www.devze.com 2023-01-02 17:44 出处:网络
i dont know why this instruccion works when i write it in this way: lv = new LoadVars(); lv.sVar1 = \"value1\";

i dont know why this instruccion works when i write it in this way:

lv = new LoadVars();
lv.sVar1 = "value1";
lv.sVar2 = "value2";
lv.onL开发者_JAVA百科oad = onLoadCallBack;
lv.sendAndLoad("http://localhost/tiempo/flash/rsstoflash.php?" + new Date(), lv, "POST");

But if a put this code into a function in this way:

function carga() {
lv = new LoadVars();
lv.sVar1 = "value1";
lv.sVar2 = "value2";
lv.onLoad = onLoadCallBack;
lv.sendAndLoad("http://localhost/tiempo/flash/rsstoflash.php?" + new Date(), lv, "POST");
}
carga();

The compiler told me:

Error opening URL 'file:///C|/webserver/www/tiempo/flash/undefined' Error opening URL 'file:///C|/webserver/www/tiempo/flash/undefined' Error opening URL 'file:///C|/webserver/www/tiempo/flash/undefined'

Any idea?


One problem might be that of scope.

When you have your var lv declared inside of a function, it's a local variable. So, it doesn't exist once the function that calls it is done.

So, this prevents lv's callback function from firing.

Assuming you have the function onLoadCallBack declared elsewhere in your code, a way to get around this would either be to declare var lv = new LoadVars(); globally (ie, outside of the function), OR to make an array or some other global container to house instances of the loaders in (if you want to have multiple running at once, say).

Something like this would look like:

var lv_array = new Array();

function carga() {
var lv = new LoadVars();
lv.sVar1 = "value1";
lv.sVar2 = "value2";
lv.onLoad = onLoadCallBack;
lv.sendAndLoad("http://localhost/tiempo/flash/rsstoflash.php?" + new Date(), lv, "POST");
}
carga();
0

精彩评论

暂无评论...
验证码 换一张
取 消