Форум Flasher.ru

Форум Flasher.ru (http://www.flasher.ru/forum/index.php)
-   Серверные технологии и Flash (http://www.flasher.ru/forum/forumdisplay.php?f=62)
-   -   Передать флеш объект в php (http://www.flasher.ru/forum/showthread.php?t=165279)

Universe 21.08.2011 17:21

Передать флеш объект в php
 
Только начинаю осваиваться с пхп и пытаюсь сделать взаимодействие с AS3. Возник вопрос, если у меня есть объект [Object object] который я хочу отдать пхп, как я могу это сделать?

Я пробую вот так:
Код AS3:

// Btn listener
submit_btn.addEventListener(MouseEvent.CLICK, btnDown);
// Btn Down function
function btnDown(event:MouseEvent):void
{       
// Assign a variable name for our URLVariables object
var variables:URLVariables = new URLVariables();
// Build the varSend variable
// Be sure you place the proper location reference to your PHP config file here
var varSend:URLRequest = new URLRequest("http://localhost/as3_php/config_flash.php");
varSend.method = URLRequestMethod.POST;
varSend.data = variables;
// Build the varLoader variable
var varLoader:URLLoader = new URLLoader;
varLoader.dataFormat = URLLoaderDataFormat.VARIABLES;
varLoader.addEventListener(Event.COMPLETE, completeHandler);
 
                  variables.uname = uname_txt.text;
                  variables.sendRequest = "parse";
                variables.testObj = {are:5, b:10, c:30};
                // Send the data to the php file
                  varLoader.load(varSend);
 
// When the data comes back from PHP we display it here               
function completeHandler(e:Event):void
{
        var phpVar3 = e.target.data.var3;
        trace(phpVar3.are);
}       
 
 
}

В пхп делаю следующее

PHP код:

<?php
// Only run this script if the sendRequest is from our flash application
if ($_POST['sendRequest'] == "parse") {
// Access the value of the dynamic text field variable sent from flash
$uname $_POST['uname'];
$testObj $_POST["testObj"];
// Print  two vars back to flash, you can also use "echo" in place of print
print "var1=The name field with a variable of $uname has been sent to PHP and is back.";
print 
"&var2=$uname is also set in variable 2 from PHP.";
print 
"&var3=$testObj";
}

?>

В итоге он мне трейсит что пришол [Object object], но при обращении к свойствам данного объекта пишет

Код:

ReferenceError: Error #1069: Property are not found on String and there is no default value.
        at MethodInfo-1()
        at flash.events::EventDispatcher/flash.events:EventDispatcher::dispatchEventFunction()
        at flash.events::EventDispatcher/dispatchEvent()
        at flash.net::URLLoader/flash.net:URLLoader::onComplete()


Андрей911 26.08.2011 06:44

Я попробовал проверить
Код AS3:

var variables:URLVariables=new URLVariables();
variables.testObj = {are:5, b:10, c:30};
variables.uname = "Universe";
variables.sendRequest = "parse";
trace(variables.testObj.are);//выводит 5
trace(variables);//выводит testObj=%5Bobject%20Object%5D&sendRequest=parse&uname=Universe

То есть ваш testObj уже изначально уходит на сервер в таком виде. Чтоб передать объект надо его предварительно преобразовать в строковое представление
Код AS3:

variables.testObj=JSON.encode({are:5, b:10, c:30});


Silicium 26.08.2011 11:26

разумеется. без сериализации/десериализации объекты как есть не передать. Только в AS JSON надо подключать, в пхп он есть нативный.


Часовой пояс GMT +4, время: 22:45.

Copyright © 1999-2008 Flasher.ru. All rights reserved.
Работает на vBulletin®. Copyright ©2000 - 2026, Jelsoft Enterprises Ltd. Перевод: zCarot
Администрация сайта не несёт ответственности за любую предоставленную посетителями информацию. Подробнее см. Правила.