A Flash Developer Resource Site

Results 1 to 5 of 5

Thread: as3 - php - as3

  1. #1
    Member
    Join Date
    May 2010
    Posts
    49

    as3 - php - as3

    Hey. I did ask this in another forum, but failed to get a reply, just thought I would let you know.

    I have a flash webpage, and on it is a form. When the user enters some details, it should go to a php page, and then display in a new webpage.

    My first swf is
    Code:
    var variables:URLVariables = new URLVariables();
    var varSend:URLRequest=new URLRequest("data.php");
    var strURL:URLRequest = new URLRequest("newBabyComplete.html");
    
    varSend.method=URLRequestMethod.POST;
    varSend.data=variables;
    
    var loader:URLLoader=new URLLoader();
    loader.dataFormat=URLLoaderDataFormat.TEXT;
    loader.addEventListener(Event.COMPLETE,messageSent);
    
    function messageSent(evt:Event):void {
    }
    
    
    sendButton.addEventListener(MouseEvent.CLICK, sendData);
    
    function sendData(e:MouseEvent):void {
    	if ((nameField.text=="") || (receiver.text=="")) {
    		messageField.text="Please complete all fields!";
    	} else {
    		variables.nameF=nameField.text;
    		variables.receiverF=receiver.text;
    		loader.load(varSend);
    		navigateToURL(strURL, "_self");
    	}
    
    	function completeHandler(e:Event):void {
    		nameField.text="";
    		receiver.text="";
    		messageField.text="";
    	}
    }
    I assume this is correct, as to sending the data to my php. I also done my navigateToURL in here, because I was unsure if I could do this in my php, and this was the only other place.

    My php is simply
    Code:
    <?php
    
    $sender = $_POST['nameF'];
    $receiver = $_POST['receiverF'];
    
    ?>
    My second webpage is supposed to receive the data from the first webpage, and display it in a text field. It looks like
    Code:
    var loader:Loader = new Loader();
    
    var myString:String;
    var myString1:String;
    
    var n:uint=1;
    var tl:MovieClip=this;
    
    
    try {
    	var keyStr:String;
    	var valueStr1:String;
    	var valueStr2:String;
    	var paramObj:Object=LoaderInfo(this.root.loaderInfo).parameters;
    	for (keyStr in paramObj) {
    		tl["valueStr"+n]=String(paramObj[keyStr]);
    		n++;
    	}
    } catch (error:Error) {
    }
    
    myString=valueStr2;
    myString1=valueStr1;
    
    loadImage();
    
    function loadImage():void {
    
    	tf.text="To "+myString;
    	tf.text="From "+myString1;
    }
    I dont get any errors, it just displays, From null. Not sure if I am doing things correctly in my first webpage in regards to navigateToURL, because then how would it have time to pass the data about?

    Just a note: Although I am calling them swf's, I am actually using their published html version.

    Any advise on how I can get this working would be appreciated.

    cheers

  2. #2

  3. #3
    Member
    Join Date
    May 2010
    Posts
    49
    Thanks for that, ammended it so it was more like one of them links you sent. It appears to me things are working correctly. Just want to see if I can do something.

    If everything is successful, I need to navigate to a new url, so I do
    Code:
    var result_data:String = String(contactLoader.data);
    	if (result_data == "ok")
    	{
    		navigateToURL(strURL, "_self");
    	}
    However, this url (which is another swf), needs the data from the swf I am in. Can I do a navigateToURL which will pass data aswell e.g.
    Code:
    var result_data:String = String(contactLoader.data);
    	if (result_data == "ok")
    	{
    		navigateToURL(strURL, "_self", "myString", "myString2");
    	}
    cheers

  4. #4
    AS3 Mod
    Join Date
    Sep 2007
    Location
    O-H-I-O
    Posts
    2,385
    There is no flash function that will pass data like that. The only thing I can think of is to send the data in a url parmeter (i.e. http://www.mysite.com/index.php?para...t&param2=test2).

    Then you would need to import those parameters into the "remote" swf using flashvars.

  5. #5
    Member
    Join Date
    May 2010
    Posts
    49
    Is there any other way I could do this? So basically, I am like making birthday cards on my website. On my first flash webpage, is a form where the user enters who the card is from and who it is too. When they click submit, the new page loads which displays the card with the users details inputted.

    Thats why I initially wanted one swf to send to a php file, and then my second swf retrieve it from this php. Would this be possible somehow without url params?

    In my second swf, I have been trying
    Code:
    var loader:Loader = new Loader();
    
    var myString:String;
    var myString1:String;
    
    var n:uint=1;
    var tl:MovieClip=this;
    
    
    try {
    	var keyStr:String;
    	var valueStr1:String;
    	var valueStr2:String;
    	var paramObj:Object=LoaderInfo(this.root.loaderInfo).parameters;
    	for (keyStr in paramObj) {
    		tl["valueStr"+n]=String(paramObj[keyStr]);
    		n++;
    	}
    } catch (error:Error) {
    }
    
    myString=valueStr2;
    myString1=valueStr1;
    
    loadImage();
    
    function loadImage():void {
    
    	tf.text="To "+myString;
    	tf.text="From "+myString1;
    }
    Can I do something like this?

    cheers

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center