dongyang9813 2010-09-04 01:15
浏览 35

将变量从Flash传递到PHP

Creating a flash project where users can visit the site, and turn off/on objects in a house (ie. lights, tv, computer, etc.) The next user who will visit the house in the website, will see what lights or house appliances were left on. Flash variables are passed to PHP, and those variables are saved in an XML file. (For testing to see what is being saved to the XML file, on each click --vars.xml opens.) In the vars.xml file, I see that the house objects that were last turned on--are saved in the XML file--BUT in the SWF file, ONLY one of the objects that are listed in the XML are turned ON. Only the last object that was clicked on would show ON--not all the objects in the XML file.)

package {
  import flash.display.MovieClip;
  import flash.events.MouseEvent;
  import flash.events.Event;
  import flash.text.*;
  import flash.net.*;

  public class House extends MovieClip {

    var request:URLRequest = new URLRequest("vars.xml")
    var loader:URLLoader = new URLLoader();


    // Constructor--------------------------------------------------------------------
    public function House()


    {

        loader.addEventListener(Event.COMPLETE, parseXML);
        loader.load(request); 

}

// function sendPhp ------------------------------------------------------------------
    function sendPhp():void
    {

        // send vars to php
        var request:URLRequest = new URLRequest("write_xml.php"); // the php file to send data to
        var variables:URLVariables = new URLVariables(); // create an array of POST vars


        for (var i:int=0; i<onList.length; i++) {
            variables["v"+i] = onList[i];
        }

        //variables['powerUsage'] = totalTxt.text;

        request.data = variables; // send the vars to the data property of the requested url (our php file)
        request.method = URLRequestMethod.POST; // use POST as the send method
        try
        {
            var sender:URLLoader = new URLLoader();
            sender.load(request); // load the php file and send it the variable data
            navigateToURL(new URLRequest("vars.xml"), '_blank'); //show me the xml
        } 
        catch (e:Error) 
        {
            trace(e); // trace error if there is a problem
        }
    }


// function parseXML ------------------------------------------------------------------

function parseXML(evt:Event)
{
    var xdata:XML = new XML(loader.data); // using E4x

    //xdata.child(0);

    for (var j:int=0; j<xdata.length(); j++) {
        onList[j] = xdata.child(j);

        for (var k:int=0; k<HouseObjects.length;k++) {
            //root[onList[j]].gotoAndStop(3);
            if (onList[j] == HouseObjects[k].name) {
                HouseObjects[k].gotoAndStop(3);
                //trace("tracing house objects"+ HouseObjects[k]);
                trace("onList[j]: " + onList[j]);
                trace("Array onList: " + onList);

            }

        }

    }

}



 } //end of class

} // end of package
  • 写回答

1条回答 默认 最新

  • dongpu8935 2010-09-05 13:39
    关注

    You actually don't need to put all this code here, and it's true that you should make your app more secure , especially after showing all this info! If your XML is not the problem , check the Actionscript part, particularly the parseXML() function.

    Are you able to trace the names of the components that are switched on? If yes , concentrate on what's happening in your loop. If your xml is fine, the problem is not passing data from PHP to Flash.

    I like the tree house! ;)

    评论

报告相同问题?

悬赏问题

  • ¥15 孟德尔随机化结果不一致
  • ¥20 求用stm32f103c6t6在lcd1206上显示Door is open和password:
  • ¥15 apm2.8飞控罗盘bad health,加速度计校准失败
  • ¥15 求解O-S方程的特征值问题给出边界层布拉休斯平行流的中性曲线
  • ¥15 谁有desed数据集呀
  • ¥20 手写数字识别运行c仿真时,程序报错错误代码sim211-100
  • ¥15 关于#hadoop#的问题
  • ¥15 (标签-Python|关键词-socket)
  • ¥15 keil里为什么main.c定义的函数在it.c调用不了
  • ¥50 切换TabTip键盘的输入法