在php页面中仅从一个打印函数获取数据并传递到flash时出现问题
我试图从php页面获取一个变量,并将其发送到flash,然后在链接中使用 我在从打印函数中选择一个变量时遇到问题,代码将帮助解释: PHP页面在php页面中仅从一个打印函数获取数据并传递到flash时出现问题,php,flash,actionscript-3,variables,Php,Flash,Actionscript 3,Variables,我试图从php页面获取一个变量,并将其发送到flash,然后在链接中使用 我在从打印函数中选择一个变量时遇到问题,代码将帮助解释: PHP页面 <? print"fbook=facebook"; print"tweet=twitter-test"; print"utube=youtube-test"; ?> var loader:URLLoader = new URLLoader(); loader.addEventListener(Event.COMPLETE,onLoaded)
<?
print"fbook=facebook";
print"tweet=twitter-test";
print"utube=youtube-test";
?>
var loader:URLLoader = new URLLoader();
loader.addEventListener(Event.COMPLETE,onLoaded);
loader.load(new URLRequest("../SC/FLA_tools-btn.php"));
var variables:URLVariables = new URLVariables();
fbook.addEventListener(MouseEvent.MOUSE_DOWN, mouseClickfbook);
tweet.addEventListener(MouseEvent.MOUSE_DOWN, mouseClicktweet);
youtube.addEventListener(MouseEvent.MOUSE_DOWN, mouseClickyoutube);
function onLoaded(evt:Event):void
{
var data:URLVariables = new URLVariables(evt.target.data);
variables.fbook = data.fbook;
variables.twitter = data.tweet;
variables.utube = data.utube;
}
function mouseClicktweet(event:MouseEvent):void
{
navigateToURL(new URLRequest('http://www.twitter.com/'+variables.twitter),"_Self");
}
function mouseClickfbook(event:MouseEvent):void
{
navigateToURL(new URLRequest('http://www.facebook.com/'+variables.fbook),"_Self");
}
function mouseClickyoutube(event:MouseEvent):void
{
navigateToURL(new URLRequest('http://www.youtube.com/'+variables.utube),"_Self");
}
它可以很好地收集所有数据,但不能正确地打印出来,它在一个链接中打印出php中的所有变量。例如:
如果我点击facebook图标,我将被带到http://www.facebook.com/facebooktweet=twitter-testutube=youtube test
其他图标(youtube和Twitter)也会出现这种情况
有什么想法吗
谢谢 从PHP通过线路发送的原始数据大致如下所示:
fbook=facebook\n
tweet=twitter-test\n
utube=youtube-test\n
fbook=facebook&tweet=twitter-test&utube=youtube-test
<?
print"fbook=facebook&tweet=twitter-test&utube=youtube-test";
?>
如果要将其与URLVariables类一起使用,则需要对属性进行正确的URL编码。它们应该是这样的:
fbook=facebook\n
tweet=twitter-test\n
utube=youtube-test\n
fbook=facebook&tweet=twitter-test&utube=youtube-test
<?
print"fbook=facebook&tweet=twitter-test&utube=youtube-test";
?>
将PHP脚本修改为如下所示:
fbook=facebook\n
tweet=twitter-test\n
utube=youtube-test\n
fbook=facebook&tweet=twitter-test&utube=youtube-test
<?
print"fbook=facebook&tweet=twitter-test&utube=youtube-test";
?>
那么,你应该把一切都安排在闪光方面。用不同的方式处理它怎么样?当您从flash应用程序请求php文件中的数据时,您可以指定所需的特定数据。以下是一个例子: Main.mxml:
<?xml version="1.0" encoding="utf-8"?>
<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
xmlns:mx="library://ns.adobe.com/flex/mx"
creationComplete="init(event)">
<fx:Script>
<![CDATA[
import flash.events.Event;
import flash.events.MouseEvent;
import flash.net.URLLoader;
import flash.net.URLRequest;
import flash.net.URLRequestMethod;
import flash.net.URLVariables;
import mx.events.FlexEvent;
import spark.components.Button;
public function init(e:FlexEvent):void
{
facebookButton.addEventListener(MouseEvent.CLICK, onClick);
twitterButton.addEventListener(MouseEvent.CLICK, onClick);
youtubeButton.addEventListener(MouseEvent.CLICK, onClick);
}// end function
private function onClick(e:MouseEvent):void
{
var button:Button = e.target as Button;
var requestString:String = "";
switch(button)
{
case facebookButton: requestString = "facebook"; break;
case twitterButton: requestString = "twitter"; break;
case youtubeButton: requestString = "youtube"; break;
}// end switch
var urlVariables:URLVariables = new URLVariables();
urlVariables.request = requestString;
var urlRequest:URLRequest = new URLRequest("http://projects.flashdevelop/stackoverflow/GetDataFromPHP/bin/php/getData.php");
urlRequest.data = urlVariables;
urlRequest.method = URLRequestMethod.POST;
var urlLoader:URLLoader = new URLLoader();
urlLoader.addEventListener(Event.COMPLETE, onUrlLoaderComplete);
urlLoader.load(urlRequest);
}// end function
private function onUrlLoaderComplete(e:Event):void
{
var urlLoader:URLLoader = e.target as URLLoader;
var urlVariables:URLVariables = new URLVariables(urlLoader.data);
trace(urlVariables.response);
}// end function
]]>
</fx:Script>
<s:HGroup>
<s:Button id="facebookButton" width="100" height="100">Facebook</s:Button>
<s:Button id="twitterButton" width="100" height="100">Twitter</s:Button>
<s:Button id="youtubeButton" width="100" height="100">Youtube</s:Button>
</s:HGroup>
</s:Application>
脸谱网
啁啾
Youtube
getData.php:
<?php
$response = "";
if (!empty($_POST))
{
switch($_POST["request"])
{
case "facebook" : $response = "response=facebook-data"; break;
case "twitter" : $response = "response=twitter-data"; break;
case "youtube" : $response = "response=youtube-data"; break;
default : $response = "response=error"; break;
}// end switch
}
else
{
$response = "response=error";
}// end else
print $response;
?>
打印的变量之间没有分隔,甚至新行也没有分隔。您正在使用php fbook=facebooktweet=TwitterTestUtube=youtube测试进行打印,那么您是否打算添加新行?在这种情况下,请在quotes.hey中的每行末尾添加\n。只是尝试添加/n。仍然做同样的事情。谢谢,我的意思是将查询分开,因为它们是相互关联的。我不确定分离器应该是什么。我不确定flash是如何准确获取php打印的。因此,&对您来说就像是一个普通的url查询。@nav当您只需要其中一个的数据时,为什么要从php文件返回facebook、youtube和twitter的数据?这就像去商店买一件衬衫,然后把它换成3种不同的尺码,最后你只需要一件你穿的尺码。嘿,伙计们,没关系,我现在就可以穿了@Taurayi正在开发一个wordpress主题,在flash中会有Fbook Twitter和Youtube按钮。我正试图让客户尽可能容易地进行设置,这样他们就可以简单地编辑一个PHP文件,而不必输入FLA文件。谢谢你的帮助!