我如何使用这样的代码迁移到 AS3 "l = new LoadVars ();"

how can I migrate to AS3 with code like this "l = new LoadVars ();"

我是初学者。我开始学习 Adob​​e Flash。我遵循了 AS2 上 Google 上的代码:

l = new LoadVars();
l.onLoad = function(ok) {
ttl0=l.ttlslv0; atc0=l.atcslv0;
ttl1=l.ttlslv1; atc1=l.atcslv1;
};
l.sendAndLoad("http:localhost/getdata.php", l, "POST"); 

与 php 像这样:

<?php
include_once("koneksi.php");
$qr = mysqli_query($con,"SELECT title, article from $tabel");
$nr = 0;
while($kolom=mysqli_fetch_row($qr) )
{ 
$ttl=$kolom[0];
$atc=$kolom[1];
echo "&ttlslv$nr=$ttl&atcslv$nr=$atc";
$nr++;
}
echo "&nr=$nr&";
?>
我可以指定 "what row" 和 "what column" 的结果。 这可以更改为具有相同结果的 AS3 吗? 我学习 AS3 有困难 有人想给我一个解决方案吗?谢谢...

在 AS3 中,您使用 URLLoader class to load text/binary data. To work with URL-encoded strings you need the URLVariables class

类似的东西(没有测试,也没有错误处理,只是一个通用的指南):

// URLRequest instance holds various information
// about what, where and how you send.
var aRequest:URLRequest = new URLRequest;

// URL address.
aRequest.url = "http://localhost/getdata.php";

// Request method (POST or GET mostly).
aRequest.method = URLRequestMethod.POST;

// URLLoader instance performs the requested operations:
// uploads the request and relevant data, reads the answer,
// and dispatches all the events about any status changes.
var aLoader:URLLoader = new URLLoader;

// Tell the URLLoader that the answer is
// an URL-encoded text of key=value pairs.
aLoader.dataFormat = URLLoaderDataFormat.VARIABLES;

// This event handler function will be triggered
// upon successfully completed operation.
aLoader.addEventListener(Event.COMPLETE, onData);

// Start loading.
aLoader.load(aRequest);

// The COMPLETE event handler function.
function onData(e:Event):void
{
    // Unsubscribe from the event. For the most part it is
    // a GOOD idea NOT to re-use any network-related
    // class instances once they've done their job.
    // Just unsubscribe from all their events,
    // dismantle their data structures, purge
    // any references to them and let the
    // Garbage Collector do his job.
    aLoader.removeEventListener(Event.COMPLETE, onData);

    // Retrieve the object that contains key=value pairs.
    var anAnswer:URLVariables = aLoader.data as URLVariables;

    // The data you wanted to get.
    trace(anAnswer.ttlslv0);
    trace(anAnswer.atcslv0);
    trace(anAnswer.ttlslv1);
    trace(anAnswer.atcslv1);
}

UPD:看来您正在处理那里的 escaped 文本。我编写了一个简单的脚本来解释它是如何工作的:

import flash.net.URLVariables;

var V:URLVariables = new URLVariables;
var S:String = "a=1&b=2";

V.decode(S);
trace(V.a); // 1
trace(V.b); // 2

S = escape(S);
trace(S); // a%3D1%26b%3D2
trace(unescape(S)); // a=1&b=2

V.decode(S); // Error #2101

因此,您可以选择两个选项:

  1. 找出服务器传递转义字符串的原因并阻止它。
  2. 将服务器的答案加载为纯文本(URLLoaderDataFormat.TEXT 而不是 VARIABLES),因此 URLLoader.data 将只是一个简单的 String,然后 unescape(...) 如果有必要,将其提供给URLVariables.decode(...).