A Flash Developer Resource Site

Results 1 to 3 of 3

Thread: flash is not loading PHP dynamically generated XML

  1. #1
    Junior Member
    Join Date
    May 2010
    Posts
    4

    Angry flash is not loading PHP dynamically generated XML

    Hi,

    I'm trying to get flash to load PHP dynamically generated XML. The flash file should display jpg images of the thumbnails in the XML file. However when I new_release.swf is not displaying any images.

    I found that flash loads fine from ordinary XML. It is not loading only from PHP dynamically generated XML.

    Does anyone know what mistake i'm making?

    The following is my flash file:
    new_release.fla

    Code:
    function loadXML(loaded) {
    if (loaded) {
    xmlNode = this.firstChild;

    thumbnails = [];
    total = xmlNode.childNodes.length;
    for (i=0; i<total; i++) {

    //thumbnails[i] = xmlNode.childNodes[i].childNodes[0].firstChild.nodeValue;
    thumbnails[i] = xmlNode.childNodes[i].firstChild.nodeValue;
    message("hello");
    thumbnails_fn(i);
    }

    } else {
    content = "file not loaded!";
    }
    }
    xmlData = new XML();
    xmlData.ignoreWhite = true;
    xmlData.load("index_test_new.php");
    xmlData.onLoad = loadXML;


    function thumbNailScroller() {
    // thumbnail code!
    this.createEmptyMovieClip("tscroller", 1000);
    scroll_speed = 10;
    tscroller.onEnterFrame = function() {
    if ((_root._ymouse>=thumbnail_mc._y) && (_root._ymouse<=thumbnail_mc._y+thumbnail_mc._heig ht)) {
    if ((_root._xmouse>=(hit_right._x-40)) && (thumbnail_mc.hitTest(hit_right))) {
    thumbnail_mc._x -= scroll_speed;
    } else if ((_root._xmouse<=(hit_left._x+40)) && (thumbnail_mc.hitTest(hit_left))) {
    thumbnail_mc._x += scroll_speed;
    }
    } else {
    delete tscroller.onEnterFrame;
    }
    };
    }

    function thumbnails_fn(k) {
    thumbnail_mc.createEmptyMovieClip("t"+k, thumbnail_mc.getNextHighestDepth());
    tlistener = new Object();
    tlistener.onLoadInit = function(target_mc) {
    target_mc._x = hit_left._x+(eval("thumbnail_mc.t"+k)._width+5)*k;
    target_mc.pictureValue = k;
    target_mc.onRelease = function() {
    p = this.pictureValue-1;
    nextImage();
    };
    target_mc.onRollOver = function() {
    this._alpha = 50;
    thumbNailScroller();
    };
    target_mc.onRollOut = function() {
    this._alpha = 100;
    };
    };
    image_mcl = new MovieClipLoader();
    image_mcl.addListener(tlistener);
    image_mcl.loadClip(thumbnails[k], "thumbnail_mc.t"+k);
    }my php file:index_test_new.php

    PHP Code:
    <?php
    header('Content-Type: application/xml');

    include("c:\bookstore\db.php");

    $cxn = @ConnectToDb($server, $user, $pass, $database);
    $table_id = 'books';
    $sql = "select title, date_format( pub_date, '%d %M %Y' ) as f_pub_date " .
    "from $table_id where MONTH(pub_date)= MONTH(CURRENT_DATE) and YEAR(pub_date) = YEAR(CURRENT_DATE) ".
    "order by f_pub_date desc";




    $result = mysql_query($sql) or die(mysql_error());

    if (mysql_num_rows($result)>0)
    { $doc = new DomDocument('1.0');

    /*$root = $doc->createElement('root');
    $root = $doc->appendChild($root);*/

    $root = $doc->createElement($table_id);
    $root = $doc->appendChild($root);

    while ($row = mysql_fetch_assoc($result))
    { $child = $doc->createElement('thumbnail');
    $child = $root->appendChild($child);

    $title_str = str_replace(' ','_',trim(strtolower($row["title"])));

    $pos = strpos($title_str,'/');

    if ($pos === false){
    $fileName = $title_str.'_sm'.'.jpg';

    if(file_exists($fileName))
    { $value = $doc->createTextNode($fileName);
    $value = $child->appendChild($value);
    }//if
    else
    {$fileName = $title_str.'_sm'.'.gif';
    if(file_exists($fileName)){
    $value = $doc->createTextNode($fileName);
    $value = $doc->appendChild($value);
    }//if
    }//else
    }//if


    else{
    $title_str2 = str_replace('/','_',$title_str2);
    $fileName = $title_str2.'_sm'.'.jpg';
    if(file_exists($fileName))
    { $value = $doc->createTextNode($fileName);
    $value = $doc->appendChild($value);
    }
    else
    {$fileName = $title_str2.'_sm'.'.gif';
    if(file_exists($fileName)){
    $value = $doc->createTextNode($fileName);
    $value = $doc->appendChild($value);
    }//if
    }//else
    }//else

    }//end while


    $xml_string = $doc->saveXML();
    echo $xml_string;


    }
    XML generated by index_test_new.php
    <?xml version="1.0" ?>
    - <books>
    <thumbnail>basic_cooking_sm.jpg</thumbnail>
    <thumbnail>dessert_recipes_sm.jpg</thumbnail>
    </books>

    i'm not able to get rid of that hypen in red above.

    thanks a lot in advance

  2. #2
    Junior Member
    Join Date
    Jun 2010
    Location
    Toronto
    Posts
    28
    If you are getting a silent error it may be a crossdomain issue; add a crossdomain file to your server root which will permit your .swf to access it.

  3. #3
    Junior Member
    Join Date
    Jun 2010
    Location
    Toronto
    Posts
    28
    ALSO, put the onLoad handler ABOVE the load action. This may be firing too late or not at all because the code always executes top to bottom, even though it loads bottom to top.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center