• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

sending variable value from php to flash to load an xml file

New Here ,
Oct 12, 2012 Oct 12, 2012

Copy link to clipboard

Copied

I would like to load an XML file from the location locally or on the server being unaware of the name of the file. I am using PHP for sending the filename to Flash.

The below is the PHP code:

<?php

filesInDir('C:\Documents and Settings\457305\My Documents\shrikant\Flash Tutorials\webassist');

function filesInDir($tdir)

{

        $dirs = scandir($tdir);

        foreach($dirs as $file)

        {

                if (($file == '.')||($file == '..'))

                {

                }

                elseif (is_dir($tdir.'/'.$file))

                {

                        filesInDir($tdir.'/'.$file);

                }

                else

                {

                        echo "fileName=$file";

                }

        }

}

?>

And below is the loading Actionscript code:

import flash.net.URLLoader;

import flash.net.URLRequest;

import flash.events.Event;

import flash.net.URLVariables;

stop();

// Define the PHP file to be loaded

var phpFile:String = "http://localhost/webassist/test.php";

var cons_xml:XML;

var xmlLoader:URLLoader = new URLLoader();

// Specify dataFormat property of the URLLoader to be "VARIABLES"

// This ensures variables loaded into Flash with same variable names

xmlLoader.dataFormat = URLLoaderDataFormat.VARIABLES;

xmlLoader.load(new URLRequest(phpFile));

xmlLoader.addEventListener(Event.COMPLETE, processXML);

function processXML(evt:Event):void

{

          trace(evt.target.data.fileName);

          //cons_xml = new XML(evt.target.data.fileName);

          //gotoAndPlay(2);

}

When I trace the evt.target.data it displays "fileName=mainOpenEndedXML%2Exml" and when I trace evt.target.data.fileName the fileName is properly displayed as "mainOpenEndedXML.xml".

But in the next two lines where the loading occurs it does not load the file i.e the swf file from xml doesn't play.

I have been searching the Internet for answers but not able to find any solutions.

The loading works properly if i directly insert the xml file in the code and the swf's in the XML file play propertly. The below is the code for the same:

import flash.net.URLLoader;

import flash.net.URLRequest;

import flash.events.Event;

import flash.net.URLVariables;

stop();

var cons_xml:XML;

var xmlLoader:URLLoader = new URLLoader();

xmlLoader.load(new URLRequest("mainOpenEndedXML.xml"));

xmlLoader.addEventListener(Event.COMPLETE, processXML);

function processXML(evt:Event):void

{

          cons_xml = new XML(evt.target.data);

          gotoAndPlay(2);

}

Any help on this would be greatly appreciated


TOPICS
ActionScript

Views

1.8K

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

LEGEND , Oct 12, 2012 Oct 12, 2012

You said you are using PHP to send the file name to Flash.  If the php file is only providing you with the name of the xml file that you need to load, then you still need to load the xml file in a similar manner as you show in your last set of code where you say you load it directly.

Votes

Translate

Translate
LEGEND ,
Oct 12, 2012 Oct 12, 2012

Copy link to clipboard

Copied

You said you are using PHP to send the file name to Flash.  If the php file is only providing you with the name of the xml file that you need to load, then you still need to load the xml file in a similar manner as you show in your last set of code where you say you load it directly.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Oct 14, 2012 Oct 14, 2012

Copy link to clipboard

Copied

I need to pull the filename dynamically via PHP and include it in the below code

xmlLoader.load(new URLRequest("mainOpenEndedXML.xml"));

as the name of the xml file will be different each time but the file will be saved in the same location.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Oct 14, 2012 Oct 14, 2012

Copy link to clipboard

Copied

Yes. you already said that, but I guess you don't understand what I said.  You are loading the PHP fle to get the filename, but nowhere are you taking that filename and loading the file that was named. 

You need to do two loading operations.  The first one to get the filename, and the second to load the file with that name.  Maybe if you name the PHP file loader phpLoader instead of xmlLoader it will start to make more sense to you.  Something like the following...

import flash.net.URLLoader;

import flash.net.URLRequest;

import flash.events.Event;

import flash.net.URLVariables;

stop();

// Define the PHP file to be loaded

var phpFile:String = "http://localhost/webassist/test.php";

var phpLoader:URLLoader = new URLLoader();

// Specify dataFormat property of the URLLoader to be "VARIABLES"

// This ensures variables loaded into Flash with same variable names

phpLoader.dataFormat = URLLoaderDataFormat.VARIABLES;

phpLoader.load(new URLRequest(phpFile));

phpLoader.addEventListener(Event.COMPLETE, processPHP);

function processPHP(evt:Event):void

{

         var xmlLoader:URLLoader = new URLLoader();

         xmlLoader.load(new URLRequest(String(evt.target.data.fileName)));

         xmlLoader.addEventListener(Event.COMPLETE, processXML);

}

var cons_xml:XML;

function processXML(evt:Event):void

{

          cons_xml = new XML(evt.target.data);

          gotoAndPlay(2);

}

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Oct 14, 2012 Oct 14, 2012

Copy link to clipboard

Copied

Thanks a ton. That really helped solve the problem

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Oct 15, 2012 Oct 15, 2012

Copy link to clipboard

Copied

LATEST

You're welcome

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines