Archive for June, 2007



18
Jun

amfPHP tutorials

Point de départ:

http://www.amfphp.org/videotuts.html

Installation et utilisation de amfPHP pour FLASH

18
Jun

lien utile flash

http://philflash.inway.fr/example.html

18
Jun

php - flex

Lien utiles pour FLEX/PHP

 

http://www.adobe.com/devnet/flex/articles/php_getstarted.html

 

18
Jun

upload d’un fichier sous Flex

file_upload.php:

PHP:
  1. <!–p<br–>   // you send messages back to the client
  2.    // and then move the file from php’s temporary upload directory to your local directory
  3.    // Filedata is the default name used in uploading
  4.    echo \nReceiving upload…\n;
  5.    echo “temporary file name = “ . $_FILES[‘Filedata’][‘tmp_name’].\n;
  6.    echo “file name = “ . $_FILES[‘Filedata’][‘name’].\n;
  7.    echo “file size = “ . $_FILES[‘Filedata’][’size’].\n;
  8.    echo “attempting to move file…\n;
  9.    move_uploaded_file($_FILES[‘Filedata’][‘tmp_name’], “./”.$_FILES[‘Filedata’][‘name’]);
  10.    echo “file moved\n;
  11. ?>

 

XML:
  1. <?xml version=“1.0″ encoding=“utf-8″?>
  2. <mx:Application xmlns:mx=“http://www.adobe.com/2006/mxml” layout=“absolute” backgroundColor=“#f6f6f6″ backgroundGradientColors=“[#f6f6f6, #bbbbbb]”>
  3.  
  4.    <mx:Label x=“10″ y=“10″ text=“File Upload” fontSize=“20″ fontWeight=“bold”/>
  5.    <mx:HRule x=“10″ y=“49″ width=“80%”/>
  6.   
  7.    <mx:Button x=“10″ y=“59″ label=“Upload” click=“{upload()}”/>
  8.   
  9.    <mx:Script>
  10.       <![CDATA[
  11.       import flash.events.DataEvent;
  12.      
  13.       public var fileRef:FileReference = new FileReference();
  14.      
  15.       public function upload():void {
  16.          // listen for the file selected event
  17.          // listen for the upload complete event
  18.          fileRef.addEventListener(Event.SELECT, selectHandler);
  19.          fileRef.addEventListener(Event.COMPLETE, completeHandler);
  20.          fileRef.addEventListener(DataEvent.UPLOAD_COMPLETE_DATA   , uploadCompleteHandler);
  21.         
  22.          // browse for the file to upload
  23.          // when user selects a file the select handler is called
  24.          try {
  25.              var success:Boolean = fileRef.browse();
  26.          }
  27.          catch (error:Error) {
  28.              trace("Unable to browse for files.");
  29.          }
  30.       }
  31.      
  32.       // when a file is selected you upload the file to the upload script on the server
  33.       public function selectHandler(event:Event):void {
  34.           var request:URLRequest = new URLRequest("upload.php")
  35.           try {
  36.              // upload file
  37.               fileRef.upload(request);
  38.               textarea1.text = "uploading " + fileRef.name + "…";
  39.           }
  40.           catch (error:Error) {
  41.               trace("Unable to upload file.");
  42.           }
  43.       }
  44.      
  45.       // dispatched when file has been given to the server script. does not receive a response from the server
  46.       public function completeHandler(event:Event):void {
  47.           trace("file uploaded complete");
  48.       }
  49.      
  50.       // dispatched when file has been uploaded to the server script and a response is returned from the server
  51.       // event.data contains the response returned by your server script
  52.       public function uploadCompleteHandler(event:DataEvent):void {
  53.           trace("uploaded… response from server: \n" + String(event.data));
  54.           textarea1.text += event.data as String;
  55.       }
  56.      
  57.       ]]>
  58.    </mx:Script>
  59.   
  60.    <mx:TextArea x=“10″ y=“89″ width=“327″ height=“134″ id=“textarea1″/>
  61.  
  62. </mx:Application>

17
Jun

Securité Flash/Flex et proxy PHP

Una alternative à cross-domain-policy est d’utiliser un script PHP de passerelle Proxy.

Une autre solution à la securité de Flash/Flex faisant appel à des webservices/loadVars et autres élements externes est de passer par un script Proxy en PHP.

 

Ce script doit être situé sur le même serveur que le Flash/Flex

il est trés simple:

$post_data = $HTTP_RAW_POST_DATA;$header[] = “Content-type: text/xml”;
$header[] = “Content-length: “.strlen($post_data);

$ch = curl_init( $_GET[‘url’] );
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_TIMEOUT, 10);
curl_setopt($ch, CURLOPT_HTTPHEADER, $header);

if ( strlen($post_data)>0 ){
    curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data);
}

$response = curl_exec($ch);    

if (curl_errno($ch)) {
    print curl_error($ch);
} else {
    curl_close($ch);
    print $response;
}

?>

Ainsi pour lire http://rss.cnn.com/rss/cnn_topstories.rss il vous suffira d’appeler :http://yoursite.com/xml_proxy.php?url=http://rss.cnn.com/rss/cnn_topstories.rss

Solution trouvée sur http://xmlrpcflash.mattism.com/proxy_info.php

17
Jun

flex downloading / telcharger un fichier

voici l’equivalent d’un a href en FLEX:

 

JAVA:
  1.       <!–DATA[<br–>      public function download():void {
  2.             var request:URLRequest = new URLRequest“http://www.drumbeatinsight.com/examples/html/HTMLComponent1.0.0.zip”);
  3.             var fileRef:FileReference = new FileReference();
  4.             fileRef.download(request);
  5.          }
  6.       ]]>
  7.  
  8.  

17
Jun

Flash / FLEX securité

Les movies fonctionnent parfaitement avec un ALT+ENTREE (en local), mais une fois publiés, les services web, les données LoadVars ou bien les HTTPServices ne fonctionnent plus.

La faute à … la securité Flash.

Solution:

Uploader sur le serveur qui contient les données loadVars, ou le webservice un fichier nommé crossdomain.xml

qui contient:

 

et voilà….

 

17
Jun

Flex avec google

Soumettre une requête à Google:

17
Jun

utiliser les accolades sous FLEX

On utilise les accolades {} pour les données sous Flex.

Il suffit d’entoure une source de données de ces accolades comme valeur dans une propriété ! 

17
Jun

communication PHP/FLEX

quelques exemples de communication Flex/PHP (Flex2.0)
          

et le code PHP peut contenir:

show_request.php: