2012-06-21 15 views
0

由於我的AS3和PHP/Java的知識不是很好,我就死在了這個問題。從動作腳本3發送可變數據給JavaScript

我有位圖數據發送到PHP文件來保存一些圖像的AS3功能,在這個功能我還添加了一些其他的參數和新的說法應該給我,我需要一個字符串值。

private function saveImageForFacebook(evt:MouseEvent) 


// Sends the Bitmap data to php  


{ 
     var bitmapData:BitmapData=new BitmapData(wheelCanvas.width, wheelCanvas.height); 
     bitmapData.draw(wheelCanvas); 
     var jpgEncoder:JPGEncoder = new JPGEncoder(80); 
     var byteArray:ByteArray = jpgEncoder.encode(bitmapData); 
     var header:URLRequestHeader = new URLRequestHeader ("Content-type", "application/octet-stream"); 
     var jpgURLRequest:URLRequest = new URLRequest ("http://www.someurl.com/flash-test/saveimg.php"); 
     jpgURLRequest.requestHeaders.push(header); 
     jpgURLRequest.method = URLRequestMethod.POST; 
     jpgURLRequest.data = byteArray; 
     navigateToURL(jpgURLRequest, "_blank"); 


// Creates the string value that I need to use in saveimg.php 


     var suffixUrl:String = ""; 
     for(var i:int=0; i < customizedColorArr.length; i++) 
     { 
      if(customizedColorArr[i] != "") 
      { 
       suffixUrl += "&" + customizedPartValueArr[i] + "=" + customizedColorArr[i]; 
      } 
     } 
     suffixUrl = wheelName + "&variant_name=" + variantName + suffixUrl; 
     trace(suffixUrl); 

    } 

不知怎的,我需要跟蹤我的saveimg.php文件中的「suffixUrl」值,但我不知道如何。

這是我的PHP文件的外觀和地方suffixUrl需要去。

<?php 
    if (isset ($GLOBALS["HTTP_RAW_POST_DATA"])) { 
    $uniqueStamp = date(U); 
    //$filename = "temp_image.jpg"; 
    $filename = $uniqueStamp . ".jpg"; 
    $fp = fopen($filename,"wb"); 
    $result = fwrite($fp, $GLOBALS[ 'HTTP_RAW_POST_DATA' ]); 
    fclose($fp); 

    } 
    ?> 
    <meta property="og:image" content="http://www.someurl.com/flash-test/src_server/<?php echo $filename ; ?>" /> 
<SCRIPT LANGUAGE="JavaScript"> 
    function redirect() { 
    window.location.href = "http://www.facebook.com/sharer.php?u=http://www.someurl/flash-test/Main3D.html?"+suffixUrl, '_self'; 
} 
</SCRIPT> 
    <BODY onload="redirect()"> 

你會在我的javascript函數中看到「suffixUrl」。那就是我試圖去探索這個價值的地方。

回答

0

你不想給一個變量發送到的Javascript;你想發送一個變量到PHP

移動後綴生成碼塊位圖發送部的上方,然後改變這一行。

var jpgURLRequest:URLRequest = new URLRequest ("http://www.someurl.com/flash-test/saveimg.php?suffixUrl=" + suffixUrl); 

然後,在PHP

window.location.href = "http://www.facebook.com/sharer.php?u=http://www.someurl/flash-test/Main3D.html?" + <?php echo $_GET['suffixUrl'] ?>, '_self'; 

這是可行的,但你也必須消毒的輸入安全

0

假設你的「PHP文件」是真實嵌入您的Flash的一個,你可以使用ExternalInterface的從Flash調用你redirect功能。

閃光燈:

ExternalInterface.call("redirect", suffixUrl); 

注意:您需要導入flash.external.ExternalInterface;

的JavaScript:

function redirect (suffixUrl) { 
    window.location.href = "http://www.facebook.com/sharer.php?u=http://www.someurl/flash-test/Main3D.html?" + suffixUrl; 
} 
+0

的問題是,我試圖傳遞的價值saveimg.php這我已經用它來保存在相同的圖片,功能。 –

+0

http://www.someurl.com/flash-test/saveimg.php –