views:

702

answers:

3

Question Updated for Bounty

In Flash I need to load a dynamically generated XML file, which is created using PHP.

I'm using the Bulk-loader library for all my loading.

Currently my Flash can only load a manually created XML file, what I need Flash to do is to load a PHP generated XML File like this:
http://dev.touchstorm.com/ten_hpn_admin2/client_user.php?id=2

When I test movie in Flash using that PHP generated XML File it will work, however the problem lies when I try to either test locally in an HTML page or online. The Flash does not render completely because of some problem obtaining data from the XML.


Here are some links to show where I'm at right now:

FLash using manually generated XML file
^ Uses: The XML file

Flash using PHP generated XML file
^ Uses: The PHP generated XML File


I searched the Bulk-loader Wiki on how to load a PHP file and for loading type information and found this: http://code.google.com/p/bulk-loader/

bulkInstance.add("http://mysite.com/top-ten.php", {type:"text"});
bulkInstance.add("http://mysite.com/top-ten.php", {type:"xml"});
bulkInstance.add("http://mysite.com/top-ten.php", {type:"image"});


CODE Snippets

Here is my current code that loads an XML file:
'theXML' variable is obtained form the FlashVars from the HTML

private function init(e:Event = null):void 
    {
        removeEventListener(Event.ADDED_TO_STAGE, init);

        stage.scaleMode = StageScaleMode.NO_SCALE;
        stage.align     = StageAlign.TOP_LEFT;
        theXML          = this.loaderInfo.parameters.theXML;
        loader          = new BulkLoader("bulky");
        loader.logLevel = BulkLoader.LOG_INFO;
        loader.addEventListener(BulkLoader.COMPLETE, onBulkLoadComplete);
        loader.addEventListener(BulkLoader.PROGRESS, onBulkLoadProgress);

        /* ------------------------------------------- TESTING */
        //Below is manual XML, works when tested local & online
        //loader.add("client_user.xml",{id:"xmldata"});

        //Below uses PHP generated XML, works when tested in Flash, but no where else
        //loader.add("http://dev.domain2.com/ten_hpn_admin2/client_user.php?id=2",{id:"xmldata", type:"xml", maxTries: 6, preventCache:true});

        /* ------------------------------------------- LIVE */
        //loader.add(theXML,{id:"xmldata"});
        loader.add(theXML,{id:"xmldata", type:"XML", maxTries: 6, preventCache:true});

        loader.start();
    }



onBulkLoadComplete code

private function onBulkLoadComplete(e:Event):void
{
trace("[BulkLoader] COMPLETE"+"\r");

Global.xml   = loader.getXML("xmldata");
HEX          = Global.xml.config.hex.toString(),{id:"hex"};
globalWidth  = Global.xml.config.width.toString();
globalHeight = Global.xml.config.height.toString();
videoHeight  = (globalHeight - (thumbMenuH + videoY + spacedBtn));
controlsY    = (videoHeight + videoY);

trace("············· Config ·············");
//trace(" HEX          = "+HEX);
//trace(" globalWidth  = "+globalWidth);
//trace(" globalHeight = "+globalHeight);
//trace("··································");
//trace("\r");

// ------------------------------------------------------ XML ARRAY
var x, i;

for(x in Global.xml.tab) {
    for(i in Global.xml.tab[x].vid) {
        videos.push(Global.xml.tab[x].vid[i].@flv);
        thumbTitles.push(Global.xml.tab[x].vid[i].@title);
        thumbPaths.push(Global.xml.tab[x].vid[i].@thumb);
    }
}

// ------------------------------------------------------ XML ARRAYS            
videoName  = videos[0]; // Current video is the 1st video

drawBackground();
drawVideo();
drawControls();
drawTabMenu();

// -------------------------------- FIND DEFAULT IMAGE/VIDEO TO LOAD
for(x in Global.xml.tab) {
    for(i in Global.xml.tab[x].vid)     {
        if (Global.xml.tab[x].vid[i].@default == "true") {
            //override any flv qued in the display
            firstTitle = Global.xml.tab[x].vid[i].@title;
            vd.flvPath = Global.xml.tab[x].vid[i].@flv;

            //load the default thumbnail
            loader = new BulkLoader("thumb");
            loader.addEventListener(BulkLoader.COMPLETE, onThumbComplete);
            loader.add(new URLRequest(Global.xml.tab[x].vid[i].@thumb),{id:"defaultThumbnail"});
            loader.start();
            break;
        }
    }
}
}

HTML Embed Code:

<div>
    <h2>Testing TEN player on external domain</h2>
    <object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,28,0" width="301" height="353">
    <param name="movie" value="http://www.domain1.com/TEN/TEN.swf"&gt;
    <param name="quality" value="high">
    <param name="flashVars" value="theXML=http://dev.domain2.com/ten_hpn_admin2/client_user.php?id=2" />
    <embed src="http://www.howdini.com/TEN/TEN.swf" flashVars="theXML=http://dev.domain2.com/ten_hpn_admin2/client_user.php?id=2" allowscriptaccess="always" quality="high" pluginspage="http://www.adobe.com/shockwave/download/download.cgi?P1_Prod_Version=ShockwaveFlash" type="application/x-shockwave-flash" width="301" height="353">
    </embed>
    </object>
</div>



Question:

1) How to load a dynamically generated XML file that ends in .php in Flash and render the Flash correctly in an HTML


UPDATE

We got the Flash to read the PHP generated XML file, however we can only view working results when we 'Test Movie' from inside Flash. When we try to get it to work in an HTML page locally or online it won't render correctly.

My PHP friend posted a part 2 of this question here from the PHP developer's perspective: http://stackoverflow.com/questions/2413266/reading-php-generated-xml-in-flash

+2  A: 

From your output:

Error #1088: The markup in the document following the root element must be well-formed.

It seems that the problem is not with the loader but with the PHP output. Check to make sure your output looks as expected by accessing the generated XML directly from your browser and downloading it. You may be able to spot the error in the output if you go through it in a text editor line-by-line, or you could try using an XML editor and see if it finds issues.

David Antaramian
Hey thanks, I'm chatting with the PHP guy now to see if we can generate the file correctly. The original XML file will load no problem, but I was also told that the mimeType needs to be text/xml, which is on the PHP side of things.
Leon
It may be as simple as one of the nodes missing a closing tag. Since the document is being generated instead of hand-written, it could be a subtlety in the code logic. The loader seems to think there is invalid syntax after the root-level element. You could try validating the document using some tool. The tool will usually specify the syntax error in the XML and the PHP guys can check where the issue is in the PHP code.
David Antaramian
Glad you got it to work :)
David Antaramian
Ugh, we got it working when you preview from Flash itself, but still having issues once it's uploaded :( http://stackoverflow.com/questions/2413266/reading-php-generated-xml-in-flash
Leon
Ok after another look at everything, the PHP developer says this is the closest answer after all :)
Leon
A: 

try put this code in the first line of you php file:

header ("content-type: text/xml");

Joan Leon
The PHP developer is still working on this, hopefully I get to test it soon!
Leon
I put this into the php file already. It was in the file originally.
AdonisSMU
Woot! Chris what did you do? I think it's working now
Leon
A: 

Are you sure you have put type:"XML" within the add of bulkloader in your online test TEN.swf, since i have an error when running it from your PHP file ?

Edit:

Reading the bytecode from your previous TEN.swf show that the xml type was not put:

0x000076  [ 0xd0 ]       GetLocal0                                                                
0x000077  [ 0x66 ]       GetProperty          QName(PrivateNamespace(""), "theXML")                                                    
0x00007a  [ 0x2c ]       PushString           "id"                                                    
0x00007d  [ 0x2c ]       PushString           "xmldata"                                                    
0x000080  [ 0x55 ]       NewObject            1                                                    
0x000082  [ 0x4f ]       CallPropVoid         QName(PackageNamespace(""), "add"), 2                                                    

Now it seems to work and showing the bytecode show that the xml type was added

0x000076  [ 0xd0 ]       GetLocal0                                                                
0x000077  [ 0x66 ]       GetProperty          QName(PrivateNamespace(""), "theXML")                                                    
0x00007a  [ 0x2c ]       PushString           "id"                                                    
0x00007d  [ 0x2c ]       PushString           "xmldata"                                                    
0x000080  [ 0x2c ]       PushString           "type"        <===== here it is now                                            
0x000083  [ 0x2c ]       PushString           "xml"         <=====                                           
0x000086  [ 0x2c ]       PushString           "maxTries"                                                    
0x000089  [ 0x24 ]       PushByte             0x6                                                    
0x00008b  [ 0x2c ]       PushString           "preventCache"                                                    
0x00008e  [ 0x26 ]       PushTrue                                                                 
0x00008f  [ 0x55 ]       NewObject            4                                                    
0x000091  [ 0x4f ]       CallPropVoid         QName(PackageNamespace(""), "add"), 2                                                    
Patrick
I believe so, according to this wiki for BulkLoader: http://code.google.com/p/bulk-loader/wiki/AvailableOptions that's where I found this snippet: bulkInstance.add("http://mysite.com/top-ten.php", {type:"xml"});
Leon
Yes you have to put it ;) The question is it really put into your TEN.swf and recompiled and online ? ==> TypeError: Error #1010
Patrick
I see that you have change your SWF with the XML type and now it work
Patrick