Welcome, Guest
  • Author Topic: load Variables From PHP to Flash  (Read 5043 times)

    Dennis

    • Server what's that
    • *
    • Posts: 8
      • View Profile
      • Email
    load Variables From PHP to Flash
    « on: 01/31/02, 23:02 »
    I've got 2 php files a master page with variables, headline, author, summary & image. And a detail page
    with the variables headline author, fullstory & image.

    I'm not to bothered about getting the images to load at the moment as I know its a pian.

    When you click on the headline the link takes you to a detail page, were the story is displayed in full.
    It all works in plain PHP, but I want it to run within a swf. What do I need to do to the php file for
    flash to load the variables?

    At the moment flash is loading the php file but not displaying the text, I've use:

    loadVariablesNum ("test_detail.php", 0);

    This is my code for the master page & the Detail page:


    Master Page:-

    <?php


    require("../../../adodb/adodb.inc.php");
    require("../../../Connections/phpnews.php");
    ?>

    <?php
    $alphaNews=$phpnews->Execute("SELECT * FROM alphabeticus") or DIE($phpnews->ErrorMsg());
    $alphaNews_numRows=0;
    $alphaNews__totalRows=$alphaNews->RecordCount();
    ?><?php
    $Repeat1__numRows = 7;
    $Repeat1__index= 0;
    $alphaNews_numRows = $alphaNews_numRows + $Repeat1__numRows;
    ?>

    <?php $MM_paramName = ""; ?><?php
    // *** Go To Record and Move To Record: create strings for maintaining URL and Form parameters

    // create the list of parameters which should not be maintained
    $MM_removeList = "&index=";
    if ($MM_paramName != "") $MM_removeList .= "&".strtolower($MM_paramName)."=";
    $MM_keepURL="";
    $MM_keepForm="";
    $MM_keepBoth="";
    $MM_keepNone="";

    // add the URL parameters to the MM_keepURL string
    reset ($HTTP_GET_VARS);
    while (list ($key, $val) = each ($HTTP_GET_VARS)) {
    $nextItem = "&".strtolower($key)."=";
    if (!stristr($MM_removeList, $nextItem)) {
    $MM_keepURL .= "&".$key."=".urlencode($val);
    }
    }

    // add the URL parameters to the MM_keepURL string
    if(isset($HTTP_POST_VARS)){
    reset ($HTTP_POST_VARS);
    while (list ($key, $val) = each ($HTTP_POST_VARS)) {
    $nextItem = "&".strtolower($key)."=";
    if (!stristr($MM_removeList, $nextItem)) {
    $MM_keepForm .= "&".$key."=".urlencode($val);
    }
    }
    }

    // create the Form + URL string and remove the intial '&' from each of the strings
    $MM_keepBoth = $MM_keepURL."&".$MM_keepForm;
    if (strlen($MM_keepBoth) > 0) $MM_keepBoth = substr($MM_keepBoth, 1);
    if (strlen($MM_keepURL) > 0) $MM_keepURL = substr($MM_keepURL, 1);
    if (strlen($MM_keepForm) > 0) $MM_keepForm = substr($MM_keepForm, 1);
    ?>



    <?php while (($Repeat1__numRows-- != 0) && (!$alphaNews->EOF))
    {
    ?>


    <A HREF="alpha_detail.php?<?php echo $MM_keepNone.(($MM_keepNone!="")?"&":"")."ID=".$alphaNews->Fields("ID")
    ?>"><?php echo $alphaNews->Fields("storyTitle")?></A>

    <?php echo $alphaNews->Fields("storyAuthor")?>

    <?php echo $alphaNews->Fields("storySummary")?>

    <img src="<?php echo $alphaNews->Fields("storyImage")?>" width="120" height="150">

    <?php
    $Repeat1__index++;
    $alphaNews->MoveNext();
    }
    ?>
    <?php
    $alphaNews->Close();
    ?>

    Detail Page:-

    <?php



    require("../../../adodb/adodb.inc.php");
    require("../../../Connections/phpnews.php");
    ?>


    <?php
    $alphaNews__MMColParam = "1";
    if (isset($HTTP_GET_VARS["ID"]))
    {$alphaNews__MMColParam = $HTTP_GET_VARS["ID"];}
    ?>


    <?php
    $alphaNews=$phpnews->Execute("SELECT * FROM alphabeticus WHERE ID = " . ($alphaNews__MMColParam)
    . "") or DIE($phpnews->ErrorMsg());
    $alphaNews_numRows=0;
    $alphaNews__totalRows=$alphaNews->RecordCount();
    ?>



    <?php echo $alphaNews->Fields("storyTitle")?>

    <?php echo $alphaNews->Fields("storyAuthor")?>

    <?php echo $alphaNews->Fields("storyDate")?>

    <?php echo $alphaNews->Fields("storyText")?>

    <img src="<?php echo $alphaNews->Fields("storyImage")?>"

    <?php
    $alphaNews->Close();
    ?>


    And also what, if any action script do I need write put in flash?

    ???

    Romwin

    • Server what's that
    • *
    • Posts: 35
    • Flash?... Whats Flash?
      • View Profile
      • Email
    Re:load Variables From PHP to Flash
    « Reply #1 on: 02/02/02, 07:42 »
    Ok, as far as the AS in the flash file... you are on the right track to pull the php information into the swf...

    onClipEvent (load) {
           loadMovieNum ("test_detail.php", 0, "GET");
    }

    All you need to add is the "GET" to the line... unless you are sending any variable, then you would want to use "POST".

    As for the PHP portion of it...
    I need to get some rest before I can really look at  it ... Ive been up all night and my brain is starting to fry...

    Romwin out...

    Flash-db

    • Administrator
    • Systems Administrator
    • *****
    • Posts: 1876
      • View Profile
      • Flash-db.com
    Re:load Variables From PHP to Flash
    « Reply #2 on: 02/02/02, 18:56 »
    Ok - I didn't look this over that carefully.  It looks like you know php really well - but may have a little trouble with the Flash side.  Hopefully these next two comments will help.

    1)  When you use LoadVariables.  Their can be nothing else printed out on the php page that you are using.  No headers, no templates, no <html> tags, Just a simple string of variables and values (after php has processed all of your request's and query's).  Sometimes it's best to type the direct URL to the file you are loading and look at the source code.

    2)  It has to be in this format.   Variable1=Value1&Variable2=Value2&Variable3=Value3....  etc etc.  

    If their is any other formatting on the page - besides just the simple string of variable/value combo's you will not be able to load those values into Flash.

    Flash is really strict about this.  You can use some limited HTML tags but they still have to be in the same format.  For example:

    Variable1=<u><b>Value1</b></u>&Variable2=<i>Value2</i>&Variable3=Value3....  etc etc

    (as an example of adding Underline, Bold, and Italic Tags. )

    A lot of really advanced programmers have trouble with this part when their first using Flash - It's not like html where it needs the <html> <body> tags or anything like that.  Just that string and nothing else on the page you are loading (after the PHP has processed all of your query's etc).  
    « Last Edit: 02/02/02, 18:57 by Jeff »
    Flash-DB

    Dennis

    • Server what's that
    • *
    • Posts: 8
      • View Profile
      • Email
    Re:load Variables From PHP to Flash
    « Reply #3 on: 02/03/02, 20:50 »
    ?
    « Last Edit: 02/04/02, 02:32 by Dennis »

    Dennis

    • Server what's that
    • *
    • Posts: 8
      • View Profile
      • Email
    Re:load Variables From PHP to Flash
    « Reply #4 on: 02/04/02, 00:52 »


    Sorry I'm not a PHP expert I use Dreamweaver & Phakt. The flash stuff I understand really well.  It's the php code thats baffling me. I looked at your code and have absolutly no Idea where goes if its complete or what to do with it.

    This is what I tried before posting this message.

    storyTitle=<?php echo $alphaNews->Fields("storyTitle")?>

    This would of work if it was plain text in a txt or html file, but php is different, could you show me, a novice what it should look like. Also do I keep all the this header stuff

    <?php
    require("../../../adodb/adodb.inc.php");
    require("../../../Connections/phpnews.php");
    ?>
    <?php
    $alphaNews__MMColParam = "1";
    if (isset($HTTP_GET_VARS["ID"]))
    {$alphaNews__MMColParam = $HTTP_GET_VARS["ID"];}
    ?>
    <?php
    $alphaNews=$phpnews->Execute("SELECT * FROM alphabeticus WHERE ID = " . ($alphaNews__MMColParam)
    . "") or DIE($phpnews->ErrorMsg());
    $alphaNews_numRows=0;
    $alphaNews__totalRows=$alphaNews->RecordCount();
    ?>


    Next question: How do I get images to display in flash from a database? I know it has to be converted to a swf, but how in flash do you create a dynamic image area? Do I have to use generator objects? Basicaly I don't know were to start.
    :D

    Musicman

    • Global Moderator
    • Systems Administrator
    • *****
    • Posts: 2685
      • View Profile
      • Email
    Re:load Variables From PHP to Flash
    « Reply #5 on: 02/04/02, 04:24 »
    Hi,

    rather than using generator, the trick is to use loadmovie into a clip - so you can position and scale the image as required. You can try out php script at www.fontimages.f2s.com/private/jpeg2swf.html for image to swf conversion without extra software - download code at www.fontimages.f2s.com/cgi-bin/jpeg2swf.cgi
    There are various other conversion tools around..

    Musicman

    Dennis

    • Server what's that
    • *
    • Posts: 8
      • View Profile
      • Email
    Re:load Variables From PHP to Flash
    « Reply #6 on: 02/25/02, 23:34 »
    This is what i was looking for

    <?php
    echo "&title=".$alphaNews->Fields("storyTitle")    
    echo "&=author".$alphaNews->Fields("storyAuthor")    
    echo "&=date".$alphaNews->Fields("storyDate")    
    echo "&=text".$alphaNews->Fields("storyText")
    ?>


    I've sorted it all out now.;D