Quantcast
Channel: Adobe Community: Message List
Viewing all articles
Browse latest Browse all 150094

Trouble setting flashvar from php page

$
0
0

I'm not sure the best way to explain this so hopefully posting the entire actionscript file isn't an issue.  I have a flash piece that records an audio recording and uses a php file to save to the server.  I need to pass a query string value to the save-file.php so was just going to do that from the PHP file using a flash var.  I already have a flashvar updating my redirectPath link but can't seem to get it to work on the saveFile var below.  At the very bottom is where I am pulling the flashvars from the PHP page.

 

Thanks in advance, I am very new to actionscript and appreciate any help you could provide!

 

-justin

 

 

 

package

{

  import flash.display.Sprite;

  import flash.media.Microphone;

  import flash.system.Security;

  import org.bytearray.micrecorder.*;

  import org.bytearray.micrecorder.events.RecordingEvent;

  import org.bytearray.micrecorder.encoder.WaveEncoder;

  import flash.events.MouseEvent;

  import flash.events.Event;

  import flash.events.ActivityEvent;

  import fl.transitions.Tween;

  import fl.transitions.easing.Strong;

  import flash.net.FileReference;

  import flash.display.LoaderInfo;

 

  // the following are needed to save the file to the server instead

  import flash.net.URLRequest;

  import flash.net.URLRequestHeader;

  import flash.net.URLRequestMethod;

  import flash.net.navigateToURL;

  import flash.net.URLLoader;

  import flash.events.DataEvent;

  import flash.events.*;

  import flash.net.*;

 

  public class Main extends Sprite

  {

  private var mic:Microphone;

  private var waveEncoder:WaveEncoder = new WaveEncoder();

  private var recorder:MicRecorder = new MicRecorder(waveEncoder);

  private var recBar:RecBar = new RecBar();

  private var tween:Tween;

  private var fileReference:FileReference = new FileReference();

  public var saveFile:String = "save-file.php";

  private var request:URLRequest = new URLRequest(saveFile);

  private var loader: URLLoader = new URLLoader();

  public var redirectPath:String = "http://localhost/thankyou.html";

 

  public function Main():void

  {

  recButton.stop();

  activity.stop();

 

  mic = Microphone.getMicrophone();

  mic.setSilenceLevel(0);

  mic.gain = 100;

  mic.setLoopBack(true);

  mic.setUseEchoSuppression(true);

  Security.showSettings("2");

 

  addListeners();

  checkFlashVars();

  }

 

  private function addListeners():void

  {

  recButton.addEventListener(MouseEvent.MOUSE_UP, startRecording);

  recorder.addEventListener(RecordingEvent.RECORDING, recording);

  recorder.addEventListener(Event.COMPLETE, recordComplete);

  activity.addEventListener(Event.ENTER_FRAME, updateMeter);

  loader.addEventListener(Event.COMPLETE,uploadCompleteDataHandler);

  }

 

  private function startRecording(e:MouseEvent):void

  {

  if (mic != null)

  {

  recorder.record();

  e.target.gotoAndStop(2);

 

  recButton.removeEventListener(MouseEvent.MOUSE_UP, startRecording);

  recButton.addEventListener(MouseEvent.MOUSE_UP, stopRecording);

 

  addChild(recBar);

 

  tween = new Tween(recBar,"y",Strong.easeOut, -  recBar.height,0,1,true);

  }

  }

 

  private function stopRecording(e:MouseEvent):void

  {

  recorder.stop();

 

  mic.setLoopBack(false);

  e.target.gotoAndStop(1);

 

  recButton.removeEventListener(MouseEvent.MOUSE_UP, stopRecording);

  recButton.addEventListener(MouseEvent.MOUSE_UP, startRecording);

 

  tween = new Tween(recBar,"y",Strong.easeOut,0, - recBar.height,1,true);

  }

 

  private function updateMeter(e:Event):void

  {

  activity.gotoAndPlay(100 - mic.activityLevel);

  }

 

  private function recording(e:RecordingEvent):void

  {

  var currentTime:int = Math.floor(e.time / 1000);

 

  recBar.counter.text = String(currentTime);

 

  if (String(currentTime).length == 1)

  {

  recBar.counter.text = "00:0" + currentTime;

  }

  else if (String(currentTime).length == 2)

  {

  recBar.counter.text = "00:" + currentTime;

  }

  }

 

  private function recordComplete(e:Event):void

   {

  request.contentType = 'application/octet-stream';

  request.method = URLRequestMethod.POST;

  request.data = recorder.output;

    loader.load( request );

   }

  private function uploadCompleteDataHandler(event:Event):void {

  navigateToURL(new URLRequest(redirectPath), "_self")

   }

  

   public function checkFlashVars():void

  {

  try {

  var keyStr:String;

  var valueStr:String;

  var paramObj:Object = LoaderInfo(this.root.loaderInfo).parameters;

  for (keyStr in paramObj){

  valueStr = String(paramObj[keyStr]);

  switch(keyStr){

  case "save":

  saveFile = valueStr;

  break

 

  case "redirecturl":

  redirectPath = valueStr;

  break

  }

 

  }

  } catch (error:Error) {

  throw(error.toString());

  }

  }

  }

}

 

PHP CODE setting the FlashVars:

var flashvars = {};

  flashvars.save = "save-file.php?mydtncode=<?php echo $_GET["mydtncode"]; ?>";

  flashvars.redirecturl = "../thankyou.php";


Viewing all articles
Browse latest Browse all 150094

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>