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
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”);
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;
}
////////////////////////////////////