# Form and Buttons within External SWF not working when loaded

**URL:** https://forum.kirupa.com/t/form-and-buttons-within-external-swf-not-working-when-loaded/315233
**Category:** Uncategorized
**Created:** [October 20, 2010, 5:58pm UTC](https://forum.kirupa.com/t/form-and-buttons-within-external-swf-not-working-when-loaded/315233 "2010-10-20T17:58:59Z")
**Posts on this page:** 1
**Page:** 1

<div class="post-metadata">

### Author: ![s7n7a7k7e](https://avatars.discourse-cdn.com/v4/letter/s/ce7236/32.png) [@s7n7a7k7e](https://forum.kirupa.com/u/s7n7a7k7e)
#### Post date: [October 20, 2010, 5:58pm UTC](https://forum.kirupa.com/t/form-and-buttons-within-external-swf-not-working-when-loaded/315233/1 "2010-10-20T17:58:59Z")

</div>

I’m currently working on a flash site, which consists of a “Main” SWF file that has buttons to load external SWF files. I figured out how to make the external SWF files show on its own layer below other layers on the main time line of the Main SWF. I created a blank movie clip file on it’s own layer of the main time line and used this to call out to it:

this.mySWFLoadingClip.addChild(loader);

This worked perfectly. The website so far works perfectly with each page of the website being an externally loaded SWF. The problem I came across today though, is that buttons and text fields within the external SWF files don’t work when they are loaded onto the “Main” SWF. They only work when I open the external SWF files individually. I really need to figure out how to make buttons and the text fields within the external SWF files when loaded onto the “MAIN” SWF. I first came across this problem when I tried adding a form that I created to one of the external SWF files called guestlist\_page\_swf.swf. The form works on its own when I open that SWF individually, but when I try to load that SWF file with the form as a page on my “Main” SWF, the mouse doesn’t even recognize that the submit button is a button, and it doesn’t allow me to click on the text fields. If you can help me understand how to make this work, I would be very grateful. Here is the link to the site I am having the problem with, and the problem page is the Guest List page:  
[www.rendezvousrestaurantsportsbar.com](http://www.rendezvousrestaurantsportsbar.com)

Below is the code from my Main SWF file and the External SWF file with the form on it:

MAIN SWF:

var Xpos:Number = 0.0;  
var Ypos:Number = 192.5;  
var swf:MovieClip;  
var loader:Loader = new Loader();

var defaultSWF:URLRequest = new URLRequest(“swfs/home\_page\_swf.swf”);

loader.load(defaultSWF);  
loader.x = Xpos;  
loader.y = Ypos;  
this.mySWFLoadingClip.addChild(loader);  
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

// Btns Universal function  
function btnClick(event:MouseEvent):void {

this.mySWFLoadingClip.removeChild(loader);  
var newSWFRequest:URLRequest = new URLRequest(“swfs/” + event.target.name + “.swf”);  
loader.load(newSWFRequest);  
loader.x = Xpos;  
loader.y = Ypos;  
this.mySWFLoadingClip.addChild(loader);  
}  
// Btn listeners  
home\_page\_swf.addEventListener(MouseEvent.CLICK, btnClick);  
about\_page\_swf.addEventListener(MouseEvent.CLICK, btnClick);  
events\_page\_swf.addEventListener(MouseEvent.CLICK, btnClick);  
menu\_page\_swf.addEventListener(MouseEvent.CLICK, btnClick);  
guestlist\_page\_swf.addEventListener(MouseEvent.CLICK, btnClick);  
contact\_page\_swf.addEventListener(MouseEvent.CLICK, btnClick);

* * *

External SWF with the Form:

stop();

// Set text formatting colors for errors, waiting…, and success mechanisms  
var errorsFormat:TextFormat = new TextFormat();  
errorsFormat.color = 0xFF0000;

var waitingFormat:TextFormat = new TextFormat();  
waitingFormat.color = 0x339900;

var successFormat:TextFormat = new TextFormat();  
successFormat.color = 0x3366FF;

// hide the little processing movieclip  
processing\_mc.visible = false;

// Assign a variable name for our URLVariables object  
var variables:URLVariables = new URLVariables();

// Build the varSend variable  
var varSend:URLRequest = new URLRequest(“[http://www.rendezvousrestaurantsportsbar.com/contact\_parse.php](http://www.rendezvousrestaurantsportsbar.com/contact_parse.php)”);  
varSend.method = URLRequestMethod.POST;  
varSend.data = variables;

// Build the varLoader variable  
var varLoader:URLLoader = new URLLoader;  
varLoader.dataFormat = URLLoaderDataFormat.VARIABLES;  
varLoader.addEventListener(Event.COMPLETE, completeHandler);

// Handler for PHP script completion and return  
function completeHandler(event:Event):void{

// remove processing movieclip

processing\_mc.visible = false;

// Clear the form fields

first\_name\_txt.text = “”;  
last\_name\_txt.text = “”;  
mailing\_txt.text = “”;

email\_txt.text = “”;

msg\_txt.text = “”;  
// Load the response from the PHP file

status\_txt.text = event.target.data.return\_msg;  
status\_txt.setTextFormat(successFormat);  
}

// Add an event listener for the submit button and what function to run  
submit\_btn.addEventListener(MouseEvent.CLICK, ValidateAndSend);

// Validate form fields and send the variables when submit button is clicked  
function ValidateAndSend(event:MouseEvent):void{

//validate form fields

if(!first\_name\_txt.length) {  
status\_txt.text = “Please enter your First Name.”;  
status\_txt.setTextFormat(errorsFormat);  
} else if(!last\_name\_txt.length) {

status\_txt.text = “Please enter your Last Name”;  
status\_txt.setTextFormat(errorsFormat);  
} else if(!email\_txt.length) {

status\_txt.text = “Please enter an Email Address”;  
status\_txt.setTextFormat(errorsFormat);  
} else if(!validateEmail(email\_txt.text)) {  
status\_txt.text = “Please enter a VALID Email Address”;  
status\_txt.setTextFormat(errorsFormat);  
} else {

// All is good so send the message to the parse file  
// Show the little “processing\_mc” movieclip

processing\_mc.visible = true;

// Ready the variables for sending  
variables.userName = first\_name\_txt.text;  
variables.userName = last\_name\_txt.text;  
variables.userEmail = email\_txt.text;  
variables.userEmail = mailing\_txt.text;  
variables.userMsg = msg\_txt.text;

// Send the data to the php file  
varLoader.load(varSend);

// Put a temporary message in the response field while the PHP file sends back  
// If the code does not connect to the PHP file this message will remain visible to user  
status\_txt.text = “Waiting for server connection…”;

status\_txt.setTextFormat(waitingFormat);

} // close else after form validation

} // Close ValidateAndSend function //////////////////////////////////////////////////////////////

// Validate email function  
function validateEmail(str:String):Boolean {  
var pattern:RegExp = /(\w|[\_.-])+@((\w|-)+.)+\w{2,4}+/;  
var result:Object = pattern.exec(str);  
if(result == null) {  
return false;  
}  
return true;  
}  
////////////////////////////////////
