swfobject

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • anfetienne
    Contributor
    • Feb 2009
    • 424

    swfobject

    is it possible to add php array to vars in the swfobject code?
  • Markus
    Recognized Expert Expert
    • Jun 2007
    • 6092

    #2
    Have a look at encoding your array with json_encode and then, using action script decode it.

    Comment

    • anfetienne
      Contributor
      • Feb 2009
      • 424

      #3
      ok thanks marcus, ill go through that once ive set my computer back up properlly

      Comment

      • Markus
        Recognized Expert Expert
        • Jun 2007
        • 6092

        #4
        Originally posted by anfetienne
        ok thanks marcus, ill go through that once ive set my computer back up properlly
        OK - let me know how you get on. Bear in mind that the link I gave you is for AS2, I think.

        Mark.

        Comment

        • anfetienne
          Contributor
          • Feb 2009
          • 424

          #5
          as the example shows for json_encode does it have to be on echo or can i assign it to a var then pass it to flash using swfobject?

          Comment

          • Markus
            Recognized Expert Expert
            • Jun 2007
            • 6092

            #6
            No - just encode and pass it as a flash var.

            Comment

            • anfetienne
              Contributor
              • Feb 2009
              • 424

              #7
              so ok does this look right to you as this is what i have......bear in mind all data is coming from a db

              Code:
              $user="theau10_tawUser";
              $pass="auction10";
              $data="theau10_resources";
              
              $connection=mysql_connect("localhost" ,"$user", "$pass") or die("Unable to connect!");
              
              @mysql_select_db($data) or die( "Unable to select database");
              
              // Select column 1 from table name where column name = $your_var.
              $sql = "SELECT * FROM savedTemps WHERE tempID = '{$random_digit}'";
              // If mysql_query returns false, we'll die with the error.
              $res = mysql_query( $sql ) or die( mysql_error );
               
              // If a there is a match
              if ( mysql_num_rows( $res ) > 0 )
              {
              $row = mysql_fetch_array( $res );
              
              }
              
              $myVar = json_encode($row);

              Comment

              • anfetienne
                Contributor
                • Feb 2009
                • 424

                #8
                and then after that i can pass $row into flash with swf object i decode it by doing

                #include "json.as"

                trace( myVar );

                varData = JSON.decode(myV ar)

                ???

                Comment

                • Markus
                  Recognized Expert Expert
                  • Jun 2007
                  • 6092

                  #9
                  Sounds about right - yes. Try it out and see.

                  Comment

                  • dmgz
                    New Member
                    • Jul 2009
                    • 6

                    #10
                    JSON.as: Line 37: Classes may only be defined in external ActionScript 2.0 class scripts.
                    class JSON {


                    what is this? how can i fix it?
                    i use flash 8

                    Comment

                    • Markus
                      Recognized Expert Expert
                      • Jun 2007
                      • 6092

                      #11
                      You should be using import class.as (I think).

                      Comment

                      • anfetienne
                        Contributor
                        • Feb 2009
                        • 424

                        #12
                        hi markus im back with some results.

                        the json prints out only 1 set of array....i have more than 1 row in my db that has the same tempID but different values for each image and the sql is just collecting the 1st set of values.

                        i called it like below:

                        Code:
                        $blank = "";
                        
                        // Select column 1 from table name where column name = $your_var.
                        $locSQL = "SELECT imageLoc FROM flashGallery WHERE tempID = '{$random_digit}'";
                        // If mysql_query returns false, we'll die with the error.
                        $locRES = mysql_query( $locSQL ) or die( mysql_error );
                         
                        // If a there is a match
                        if ( mysql_num_rows( $locRES ) > 0 )
                        {
                        $locAry = mysql_fetch_array( $locRES );
                        
                        }
                        else{
                        echo $blank;
                        }
                        
                        
                        $locVar = json_encode($locAry);
                        
                        // Select column 1 from table name where column name = $your_var.
                        $tmbSQL = "SELECT thumbLoc FROM flashGallery WHERE tempID = '{$random_digit}'";
                        // If mysql_query returns false, we'll die with the error.
                        $tmbRES = mysql_query( $tmbSQL ) or die( mysql_error );
                         
                        // If a there is a match
                        if ( mysql_num_rows( $tmbRES ) > 0 )
                        {
                        $tmbAry = mysql_fetch_array( $tmbRES );
                        
                        }
                        else{
                        echo $blank;
                        }
                        
                        $tmbVar = json_encode($tmbAry);
                        
                        // Select column 1 from table name where column name = $your_var.
                        $capSQL = "SELECT imageLoc FROM flashGallery WHERE tempID = '{$random_digit}'";
                        // If mysql_query returns false, we'll die with the error.
                        $capRES = mysql_query( $capSQL ) or die( mysql_error );
                         
                        // If a there is a match
                        if ( mysql_num_rows( $capRES ) > 0 )
                        {
                        $capAry = mysql_fetch_array( $capRES );
                        
                        }
                        else{
                        echo $blank;
                        }
                        
                        $capVar = json_encode($capAry);
                        
                        mysql_close();
                        
                        $flashVar1 =  'so.addParam("locVar", "'.$locVar .'");';
                        $flashVar2 =  'so.addParam("tmbVar", "'.$tmbVar .'");';
                        $flashVar3 =  'so.addParam("capVar", "'.$capVar .'");';
                        sql is only returning the 1st row?

                        Comment

                        • anfetienne
                          Contributor
                          • Feb 2009
                          • 424

                          #13
                          i've decided to json_encode the necessary details before saving it to a db. im having trouble retrieving all data needed into an array as everything i have tried either shows the 1st or last row that is retrieved instead of all rows

                          Comment

                          • anfetienne
                            Contributor
                            • Feb 2009
                            • 424

                            #14
                            ive fixed it here is the solution

                            Code:
                            // Select column 1 from table name where column name = $your_var.
                            $locSQL = "SELECT imageLoc, thumbLoc, imageCap FROM flashGallery WHERE tempID = '{$random_digit}'";
                            // If mysql_query returns false, we'll die with the error.
                            $locRES = mysql_query( $locSQL ) or die( mysql_error );
                             
                            // If a there is a match
                            if ( mysql_num_rows( $locRES ) > 0 )
                            {
                            
                            	while($row = mysql_fetch_array($locRES,MYSQL_ASSOC)){
                            	
                            	$aryA[]=$row['imageLoc'];
                            	$aryB[]=$row['thumbLoc'];
                            	$aryC[]=$row['imageCap'];
                            		
                            	} 
                            }
                            	$locAry = implode($aryA);
                            	$tmbAry = implode($aryB);
                            	$capAry = implode($aryC);
                            	
                            $flash02="so.addVariable('locVar', '$locAry'); so.addVariable('tmbVar', '$tmbAry'); so.addVariable('capVar', '$capAry');";
                            
                            mysql_close();
                            ?>

                            Comment

                            • dmgz
                              New Member
                              • Jul 2009
                              • 6

                              #15
                              what's the action script code?
                              i don't know how to decompile the json code into flash :|

                              Comment

                              Working...