# Receiving a variable from php

**URL:** https://forum.kirupa.com/t/receiving-a-variable-from-php/315782
**Category:** flash
**Created:** [November 3, 2010, 9:31pm UTC](https://forum.kirupa.com/t/receiving-a-variable-from-php/315782 "2010-11-03T21:31:49Z")
**Posts on this page:** 1
**Page:** 1

<div class="post-metadata">

### Author: ![mark\_bcn](https://avatars.discourse-cdn.com/v4/letter/m/a4c791/32.png) [@mark\_bcn](https://forum.kirupa.com/u/mark_bcn)
#### Post date: [November 3, 2010, 9:31pm UTC](https://forum.kirupa.com/t/receiving-a-variable-from-php/315782/1 "2010-11-03T21:31:49Z")

</div>

Hello kirupees,

I just build a simple web server, but now in one of the pages I would have to have a flash (.swf) embbeded.  
Maybe an easy task, but also I would like that the .swf receives data from the PhP page, but I cant figure how ☹

Simply that when I push the button in the .swf, the sampletext changes to a variable name I have in php.

I asure you that I’ve tried more than 15 tutorials or guides, and searched a lot of forums so please understand my frustation.

If anyone knows how I would appreciate so much the help.  
Thanks a lot in advance.

**PHP Page**

> 

\<html\>  
\<body\>

\<h1\>\<center\>SAMPLE PAGE\</center\>\</h1\>

\<?php  
//getting the variable I want to send to flash  
$username = $\_SESSION[‘playername’];  
//send variable to Flash(?)  
echo $username;

echo ‘\<object width=“800” height=“600”\>\<param name=“movie” value=“test.swf”\>\<embed src=“test.swf” width=“800” height=“600”/\>\</object\>’;  
?\>

\</body\>  
\</html\>

**FLASH AS3**

> 

import flash.events.\*;  
import flash.net.URLLoader;  
import flash.net.URLLoaderDataFormat;  
import flash.net.URLRequest;  
stop();

button.buttonMode = true;  
button.addEventListener(MouseEvent.CLICK, clicked);

function clicked (event:MouseEvent):void {  
var request:URLRequest = new URLRequest(“[http://localhostroomSolid.php](http://localhostroomSolid.php)”);  
request.method = URLRequestMethod.POST;

```
var loader:URLLoader = new URLLoader();
loader.dataFormat = URLLoaderDataFormat.VARIABLES;
loader.addEventListener(Event.COMPLETE, completeHandler);
loader.load(request);

function completeHandler(evt:Event) {
      var username = evt.target.data.username;
    sampletext.text = username;
}

```

}

pd: as I have very little code I quoted it so you can have a better idea, again, thanks
