开发者

Easy way to bring a php variable on flash with AS2

开发者 https://www.devze.com 2023-01-01 12:09 出处:网络
Can you show me an example of a very easy implementation in AS2 (action script 2.0) to bring a var from a php file. I have a php script who return a value into the var $result when it is executed, how

Can you show me an example of a very easy implementation in AS2 (action script 2.0) to bring a var from a php file. I have a php script who return a value into the var $result when it is executed, how can i use this var on fla开发者_如何转开发sh? Thanks


AS2 LoadVars method.

LoadVars load example

// init LoadVars Object
lv = new LoadVars();

// define onLoad Callback
lv.onLoad = onLoadCallBack;

// send and load variables
lv.load("http://localhost:2400/lv.txt?" + new Date());

// onLoad Callback
function onLoadCallBack(succes)
{
    // if succes
    if(succes)
    {
        // trace variables
        trace(this.lVar1);
        trace(this.lVar2);
    }
    else
    {
        // loading failed
        trace("Loading Error!!");
    }
}

/*LoadVars send example*/
// init LoadVars Object
lv = new LoadVars();

// set Variables
lv.sVar1 = "value1";
lv.sVar2 = "value2";

// define onLoad Callback
lv.onLoad = onLoadCallBack;

// send and load variables
lv.sendAndLoad("http://localhost:2400/lv.php?" + new Date(), lv, "POST");

// onLoad Callback
function onLoadCallBack(succes)
{
    // if succes
    if(succes)
    {
        // trace variables
        trace(this.lVar1);
        trace(this.lVar2);
    }
    else
    {
        // loading failed
        trace("Loading Error!!");
    }
}

PHP code

<?
    // get variables
    $var1 = $_POST['sVar1'];
    $var2 = $_POST['sVar2'];

    // send variables
    echo "&lVar1=$var1 returned&";
    echo "&lVar2=$var2 returned as well&";
?>

source: http://snipplr.com/view/8878/as2-loadvars-php-example/

0

精彩评论

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