簡體   English   中英

Flash AS3從PHP返回未定義的變量

[英]flash AS3 returning undefined variables from PHP

我試圖從PHP提取一些數據並在Flash AS3中的鏈接中使用它們。

閃存代碼:

var loader:URLLoader = new URLLoader();
loader.addEventListener(Event.COMPLETE,onLoaded);
loader.load(new URLRequest("FLA_connect.php"));
var variables:URLVariables = new URLVariables();
signup.addEventListener(MouseEvent.MOUSE_DOWN, mouseClick);

function onLoaded(evt:Event):void
{
var data:URLVariables = new URLVariables(evt.target.data);
variables.sponny = data.spon;


}

function mouseClick(event:MouseEvent):void
{
navigateToURL(new URLRequest('http://www.website.com/'+variables.sponny),"_self");
}

FLA_connect.php代碼:

<?php

require ('config.php');

print "spon=$username";

?>

我已經測試了FLA_connect.php,它返回了正確的數據,但是在Flash中進行測試時,該變量返回為undefined,因此我最終獲得了鏈接www.website.com/undefined。

有什么想法的家伙嗎?

謝謝

對於shanethehat

<?

require ('../config/db_4554651684654548784216.php'); //DB connection info is stored
require ('conf_id.php'); //this file holds the value for $lead_reference

mysql_connect($hostname,$username,$password) or die(mysql_error());
mysql_select_db($dbname) or die(mysql_error());

$get__id_check = mysql_query("SELECT * FROM $usertable WHERE ". "idEmail_lead = '$lead_reference'");

while($id__check = mysql_fetch_array($get__id_check)) {
    $first_N = $id__check["First_Name"];
    $last_N = $id__check["Last_Name"];
    $email_add = $id__check["Email"];
    $GDI__username = $id__check["GDI_Username"];


 }


?>

我自己遇到了這個錯誤和問題。 我檢查過重新檢查並重新編碼了5次腳本,以為是我的錯或代碼錯誤。 我已經弄清楚了代碼的哪一部分給出了未定義的變量。 它在結果功能區中。

function showresult(event:event) {
 txtbox.text = "" + event.target.data.spon;
}

管他呢。 代碼偶數未在even.target.data部分中定義,這會導致未定義的錯誤。 現在對我來說,我將event.target.data.myresult更改為event.target.data,並且能夠看到php文件的文本。

但是在將myresult添加到文件時無法從文件獲得響應。 如果有人對這個問題有其他有用的信息,請告訴我。 我也嘗試將toString添加到myresult上,但是它給出了一個很大的錯誤,並再次指向未定義的myresult。

您是否嘗試過直接訪問data的變量? 您還需要告訴您的加載器期望URL編碼的變量:

var loader:URLLoader = new URLLoader();
loader.dataFormat = URLLoaderDataFormat.VARIABLES;
loader.addEventListener(Event.COMPLETE,onLoaded);
loader.load(new URLRequest("FLA_connect.php"));

function onLoaded(evt:Event):void
{
    (ExternalInterface.available) ? ExternalInterface.call("console.log","Incoming data:" + evt.target.data) : trace("Incoming data:" + evt.target.data);
    variables.sponny = evt.target.data.spon;
}

如果失敗,請從跟蹤evt.target.data的值開始,以確保您從PHP中獲得了收益,並且在單擊注冊按鈕之前等待了足夠長的時間以等待數據返回。加載數據時僅顯示“注冊”按鈕可能會更好

如果包含config.php導致失敗,則說明配置文件中有錯誤
HTTP://myserver.com/FLA_connect.php directly from a browser調用HTTP://myserver.com/FLA_connect.php directly from a browser
您應該會看到erorr報告

現在針對第二部分或您的問題
在你的PHP頁面
您正在返回一個字符串

spon=XXXXXXX

因此,您應該在動作腳本方面將其解析為字符串,而不是對象。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM