PDA

View Full Version : Automate button press


holtzy
05-11-2004, 08:17 PM
I have an html page with both a flash movie and an html form included. Is there any possible way to automate pressing a button on the html form when the user clicks a button in the flash movie? Thanks!

CyanBlue
05-12-2004, 08:46 AM
Howdy... :)

I know pretty much zippo about the HTML but here is an idea... :D
When you create the HTML form, have the submit button execute some JavaScript function as you do with the form validation stuff, and remember what that JavaScript function name is...
And, when you have to emulate the clicking on the button, maybe you could run that JavaScript function via getURL() call from the Flash???

holtzy
05-12-2004, 09:26 AM
Sounds like that just might work. You mean have it setup something like this...<SCRIPT language="JavaScript">
function submitform()
{
document.myform.submit();
}
</SCRIPT>Then from Flash call the submitform() funtion via getURL, right? I'll give it a shot. Thanks!

CyanBlue
05-13-2004, 08:45 AM
Hm... Sounds like I might actually have said something useful... Let me know how it goes and what the exact command was... :)

tg
05-13-2004, 10:39 AM
what???!!! you mean to say that outta 8973+ posts, this is the first usefull thing you've said??? i'm gonna havfta add you to my ignore list now.

CyanBlue
05-13-2004, 11:14 AM
Shhhhhh... That's supposed to be one of the secrets in the AS.org... :D

holtzy
05-13-2004, 08:12 PM
Ok, evidently I have to use a specific way to upload a file for security reasons. So now I am simply try to detect when the upload button has been pressed. There has to be a simple way to do this. I know when the button is pressed that it is given the value "Upload", so if I can check for this value somehow then I can do it. I found something about If Request.Form("submit") = "Upload" thenbut i'm not sure if this works in PHP, cause i think this code i found is ASP. Here is the excerpt of code in my php/html page<form method=POST action=do_upload.php enctype=multipart/form-data>
<p>Upload Picture:<br>
<input type=file name=img1 size=30><br>
<input type="submit" name="submit" value="Upload">
<p><font color=red>(This could take a couple minutes depending on the size of your picture)</font>
<input type=hidden name=VehicleID value="<?php echo $VehicleID ?>">
</form>

I guess I need to know how to refer to the button on the form so i can check for it's value.

If Request.Form("submit") = "Upload" then
echo "testing";
end if

I guess I need to know how to refer to the form button so i can check it's value cause i can't get Request.Form to work...

petefs
05-13-2004, 08:26 PM
I've developed a WYSIWYG flash backend for a client's flash site, and what you're doing is possible certainly : )

Is this a file upload? If so, you're going to be restricted to internet explorer only. Mozilla/Netscape, and presumably other browsers (not tested) consider using the javascript element click() method to trigger an upload "Browse" button a security problem. Here's the script from that site:

index.html:

<html>
<head>
<title>MyClient Admin</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>

<frameset cols="100%,0" frameborder="NO" border="0" framespacing="0">
<frame name="main" scrolling="AUTO" noresize src="flash.php">
<frame name="controller" scrolling="NO" noresize src="upload.php">
</frameset>
<noframes><body bgcolor="#FFFFFF" text="#000000">

</body></noframes>
</html>

upload.php:

<?php
header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
header("Cache-Control: no-store, no-cache, must-revalidate");
header("Cache-Control: post-check=0, pre-check=0", false);
header("Pragma: no-cache");

if(isset($_POST['fileup'])==true) {
require("hft_uploader.php");
require("hft_image.php");
require("class.cropcanvas.php");
$filenames=array();
foreach($HTTP_POST_FILES as $key=>$value)
{
if($HTTP_POST_FILES[$key]['tmp_name']!="")
{
$uploader = new hft_uploader($key, "../images", "image/jpeg image/pjpeg", 1000000, 108);
$filename = time().rand(1,10).$uploader->original_name;
$filenames[] = array($key, $filename);
if($uploader->store_upload($filename))
{
$original_image = "../images/".$filename;
switch($key)
{
case ("itemFullUF"):
case ("diningItemFullUF"):
$width = 320;
$height = 240;
break;
case ("catTnUF"):
case ("diningItemTnUF"):
$width = 80;
$height = 60;
break;
default:
$width = 64;
$height = 48;
}
$image = new hft_image($original_image);
$image->resize($width, $height, '+');
$image->output_resized($original_image, "JPEG");
$cc = new canvasCrop();
$cc->loadImage($original_image);
$cc->cropToSize($width,$height,ccCENTRE);
$cc->saveImage($original_image);
chmod("../images/".$filename, 0644);
}
}
}
}
?>
<html>
<head>
<title>Upload</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<SCRIPT LANGUAGE=JavaScript>
<!--

function upit(fld)
{
var upObj = eval("document.forms.upload."+fld);
upObj.click()
while(upObj.value == "")
{
setTimeout(100)
}
upControl(fld)
}

function submitIt(){
document.upload.submit()
}

function upControl()
{
var obj=parent.main.admin;
var re = new RegExp("\\\\", "g");
for (var i=0; i<document.upload.elements.length; i++)
{
if(document.upload.elements[i].type=="file" && document.upload.elements[i].value!="")
{
var fileval = document.upload.elements[i].value;
var retSt = fileval.replace(re, "/");
if (obj) eval('obj.SetVariable("_root."+document.upload.elements[i].name, "' + retSt + '")');
}
}
}
<?php
if(count($filenames)>0) {
?>
var obj=parent.main.admin;
<?
foreach($filenames as $key=>$value)
{
?>
if (obj) eval('obj.SetVariable("_root.<?php echo $filenames[$key][0]; ?>", "<?php echo $filenames[$key][1]; ?>")');
<?php
}
?>
if (obj) eval('obj.SetVariable("_root.UF", "<?php echo $filenames[0][0]; ?>")');
window.location="bounce.php";
<?php
}
?>
//-->
</SCRIPT>
</head>

<body bgcolor="#000000" text="#FFFFFF">
<form name="upload" enctype="multipart/form-data" method="post" action="uploader.php">
<input type="file" name="catTnUF">
<input type="file" name="itemTnUF">
<input type="file" name="itemFullUF">
<input type="file" name="diningItemTnUF">
<input type="file" name="diningItemFullUF">
<input type="hidden" name="fileup" value="yes">
<input type="submit" value="Submit it">
</form>
</body>
</html>

bounce.php

<?php
header("Location: http://www.hostfs.net/lubahati.com/admin/uploader.php");
exit;
?>

flash.php:

<html>
<head>
<SCRIPT LANGUAGE=JavaScript>
<!--
function upit(fld)
{
var upObj = eval("parent.controller.document.forms.upload."+fld);
upObj.click()
while(upObj.value == "")
{
setTimeout(100)
}
parent.controller.upControl()
}

function submitIt(){
parent.controller.document.upload.submit()
}
//-->
</SCRIPT>
<title></title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body bgcolor="#0d155e">
<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,0,0" width="800" height="650" id="admin" align="middle">
<param name="allowScriptAccess" value="sameDomain" />
<param name="movie" value="admin.swf?<?php echo time(); ?>" />
<param name="quality" value="high" />
<param name="bgcolor" value="#0d155e" />
<embed src="admin.swf?<?php echo time(); ?>" quality="high" bgcolor="#0d155e" width="800" height="650" name="admin" align="middle" swliveconnect=true allowScriptAccess="sameDomain" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" />
</embed>
</object>
</body>
</html>

Now obviously this is a little more complicated than it should be, but that's because it's meant to handle a variety of different fields smartly from flash. Also the bounce is not necessary, but I use it to make sure if the client uses the 'refresh' button on their browser or hits F5 it doesn't:
A) nag them with the 're-post form data' confirmation
B) re-post the form data!

If you have any problems slimming that code down, or have problems with the flash side, let me know : ) I may be a while, I just got busy and I'm going to be away for the weekend, but that's the general idea!

holtzy
05-13-2004, 08:56 PM
Thanks for the info and the sample code, but I'm afraid I can't limit myself to just IE. There has to be a way to detect simply when the button is pressed...doesn't there?

petefs
05-13-2004, 09:50 PM
you can submit the form in any browser, but you cannot click the 'browse' button. mozilla/netscape consider that a security issue so it isn't supported. I'm thinking of trying to write a div layer with document.write and have that div layer positioned on top of the flash file, then you can actually click the button, but I'm not sure the div layer will display over the flash object -- has anybody tried this?

holtzy
05-13-2004, 09:55 PM
Oh, my mistake. I will give it a shot then. Thanks again! I'll let you know what happens...

holtzy
05-13-2004, 10:02 PM
could you maybe zip up & post the admin.fla? and what is uploader.php?

ok, i am totally lost. When I open up the index.html page it prompts me to download the upload.php file, then if i click ok, it simply opens the upload.php file in notepad.

CyanBlue
05-13-2004, 10:31 PM
but I'm afraid I can't limit myself to just IE.
Welcome to the fantastic world of the computing... :D
have that div layer positioned on top of the flash file, then you can actually click the button,
Obviously, I am not getting it at all, but this is what I have done to test something a couple of days ago... See if this is what you are looking for or not... (I don't have the file, so I'll have to post it tomorrow if I don't forget... :D)
I have three buttons(<A> tag) in the HTML page which hides other DIV layers and make the specified DIV layer visible, so, Btn1 makes the DIV layer 1 visible and so on...
DIV layer 1 contains a Flash file, and DIV 2 contains an image, and DIV 3 contains some website... So, the idea was to make the Flash layer visible/invisible depending on the condition... Tell me if it is what you are looking for, petefs, and I'll post the code if it is... ;)

holtzy
05-13-2004, 11:10 PM
ok, back to the old way i was trying to accomplish this....

The php code if ($_POST["submit"] == "Upload") {
$CheckedUpload = "completed";
}tells me when the submit button is clicked (it works I've tested it). Now my problem is sending this variable to my flash movie in a different window. Is it possible to have flash constantly checking for a change in this variable? I've tried having an onEnterFrame thing with a sendAndLoad to the php file, but it's not working. It never gets the variable from the php. Any ideas?

CyanBlue
05-13-2004, 11:23 PM
this variable to my flash movie in a different window
Hm... On top of my head, I'd use LocalConnection to send the value...
The pseudo code would be something like this... (Sorry, too tired...)

if ($_POST["submit"] == "Upload") {
// Meaning that the upload is done, right???
echo("EMBED String here...");
echo("What it embed is a 1 x 1 SWF file that's sole purpose is");
echo("to send something to the SWF file in another window");
// Once the 1 x 1 SWF file talks to the other SWF, that SWF should
// be able to do the necessary process something like saying
// 'Thank you for the upload blah blah' or similar...
}Basically that's how I have done the file upload stuff with PHP long time ago... So, I could probably say that it should work... :)

holtzy
05-13-2004, 11:56 PM
That makes sense, but how do i tell the embedded flash file to send the variable to my other swf? Do i embed it in the if statement as you listed above? Doesn't it have to be inside the body tags? Sounds like i'm back to my original problem...php/html talking to a flash movie, eventhough it's embedded in the same page. I think it's just late, but I can't figure it out. I don't understand what triggers the embeded flash swf to talk to the other swf.

petefs
05-14-2004, 01:51 AM
oh, you just want two .swfs to talk to each other?

Use a LocalConnection : )

http://www.actionscript.org/tutorials/intermediate/LocalConnections/index.shtml

petefs
05-14-2004, 02:04 AM
Woops, I missed some posts there!

::CyanBlue:: I'd like to see the file, I think it could overcome the crossbrowser issue and be far less 'hacky'

::Holtzy::
To send a variable to flash from a website just use FSCommand

Take a look at my upload.php file, here's a simplified verison:

var obj=parent.main.admin;
if (obj) obj.SetVariable("_root.myFilename", "this is the filename!");

in this case it's referencing the admin.swf in the 'main' frame, but it could as easily be in the same frame:

var obj = document.admin;

To insure that flash knows when the variable you want to use a watch. Here's an example (in _root scope):

checkUFile = function(name, oldval, newval){
var returnVal = newval;
return returnVal;
}
this.watch("myFilename",checkUFile);

You can add anything to the watch callback function that you want, of course : ) the three arguments sent by watch are the name of the variable, the old value, and the new value (as illustrated by the arg list).

I know I'm missing something else I wanted to tell you, but I have a lot of work to do unfortunately ^_^

I unfortunately can't post the .FLAs for you because it's a client's backend, but I <CAN> make way simplified version for you after this weekend (I'll be gone for the weekend). I'll use it as a chance to try the div layer trick and make it crossplatform.

Hope I helped in my rambling :D

CyanBlue
05-14-2004, 09:35 AM
Here is the DIV stuff that I had... Still not sure if this is somthing that can help you, but at least I try... :D (You do need to change the URL for the iframes and the SWF as well...)
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>divTest</title>
<script type="text/javascript">
function show_div(div_id) {
// hide all the divs
document.getElementById('the_div_1').style.display = 'none';
document.getElementById('the_div_2').style.display = 'none';
document.getElementById('the_div_3').style.display = 'none';

// show the requested div
document.getElementById(div_id).style.display = 'block';
}
</script>
</head>

<body>
<a href="" onclick="show_div('the_div_1'); return false;">Div 1</a>
<a href="" onclick="show_div('the_div_2'); return false;">Div 2</a>
<a href="" onclick="show_div('the_div_3'); return false;">Div 3</a>

<div id="the_div_1">
This is div 1<BR>
<OBJECT classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"
codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,79,0"
WIDTH="300" HEIGHT="231" id="Travel" ALIGN="">
<PARAM NAME=movie VALUE="Travel33.swf">
<PARAM NAME=quality VALUE=high>
<PARAM NAME=bgcolor VALUE=#333333>
<EMBED src="Travel33.swf"
quality=high
bgcolor=#333333
WIDTH="300"
HEIGHT="231"
NAME="Travel"
ALIGN=""
TYPE="application/x-shockwave-flash"
PLUGINSPAGE="http://www.macromedia.com/go/getflashplayer">
</EMBED>
</OBJECT>
</div>

<div style="display: none;" id="the_div_2">
This is div 2<BR>
<iframe src="http://deskwx.weatherbug.com/Travel/Travel.aspx?curr_tab=1&ctl_sel=4&lvl=$$LVL$$&flash=True&zip_change=27601&zone=NC041&zip=27601" width="300" height="231"
frameborder="0" scrolling="auto" name="myInlineFrame">
This is div 2</iframe>
<BR>
</div>

<div style="display: none;" id="the_div_3">
This is div 3<BR>
<iframe src="http://deskwx.weatherbug.com/YourPhotos/YourPhotos.aspx?curr_tab=1&lvl=$$LVL$$" width="300" height="231"
frameborder="0" scrolling="auto" name="myInlineFrame">
This is div 2</iframe>
<BR>
</div>
</body>
</html>Do i embed it in the if statement as you listed above? Doesn't it have to be inside the body tags?Um... Yes, within the if statement block if your PHP script is within the BODY tag... If not, move that echo block down below to the BODY tag... You could do something like this then... if (upload)
{
$flash = "YOUR EMBED STRING HERE";
}
else
{
$flash = "";
}
and within the BODY tag...
<BODY ... ... ...>
<?php echo($flash); ?>
</BODY>
I don't understand what triggers the embeded flash swf to talk to the other swf.
On the tutorial that petefs mentioned, the actual line that sends out the string to another SWF is this one, right???talkingLC.send("simple_lc", "comeBack", speech);Add that line in the first frame of the 1 x 1 SWF that you embed into the Flash and it should automatically fire the call as soon as SWF gets fully loaded and your other SWF should be able to get that string...


As for the watch() function... Somehow I never had a chance to use it even if I used the Flash long enough... I like trace() and outputting to the textbox better if that's any similar to the watch() function... :D


One question though... It looks like you are doing the upload stuff... Basically YamzBrowser component does the very same thing that I have mentioned... Why not use that and try to modify the JavaScript part in there so that it could be used in more browsers??? Or would that be harder??? Dunno... :D

petefs
05-14-2004, 09:59 AM
watch() detects any change in the variable and fires off an event -- in this case any time the _root scope variable myFilename is changed the function checkUFile is called with those three args. It's particularly handy in knowing when your file is finished uploading since there's no way to get an actual progress report in an .swf : /

And since my code works in as many browsers as YamzBrowser does I'll probably continue along those lones : ) The key is that the button has to actually be pressed, not told that it's pressed by JS ^^ No problem if you wanna REALLY fake it bad, but I want it to really seem like it's in flash ^_^

Man, I'm tired and my ride to the airport is late : / how fast can you drive? :b

CyanBlue
05-14-2004, 10:03 AM
Hm... Okay... Still not sure if I ever will use that watch() function but thanks for the explanation... :)

As for faking the button click... Make people press hard on the mouse buttons... Tha's good for the economy... :D

I think I could probably there in, um, 6 hours... Going somewhere good??? I'd love to tag along if it is the case... ;)

Oh... Did that DIV tag do any help???

petefs
05-14-2004, 10:07 AM
I have not the brain for looking at it, I've been up all night finishing a project and preparing for the trip.

I'm going to Madison for the weekend to see my younger sister graduate ^_^ So pretty nice, but not too much fun... I'm about to drive myself and pay for parking, traffic aint too hot at the beach in summer on a friday. (at least it's all incoming) ^_^

CyanBlue
05-14-2004, 10:14 AM
Hehe... Not a problem... :)

Madison, WI??? Enjoy the trip... I hope the weather is not bad for your family... Forecast for: Madison, WI 53701

Today
Occasional showers and isolated thunderstorms diminishing in the afternoon. Highs in the upper 50s. Northwest winds 10 to 15 mph.
Tonight
Partly cloudy. Scattered frost after midnight. Cooler. Lows in the upper 30s. Northwest winds 10 to 15 mph decreasing to 5 to 10 mph after midnight.
Saturday
Partly cloudy. Highs in the mid 60s. Northeast winds around 10 mph shifting to the southeast 5 to 10 mph in the afternoon.
Saturday Night
Partly cloudy. Lows in the mid 40s. South winds 5 to 10 mph increasing to 10 to 15 mph after midnight.
Sunday
Partly cloudy. A 30 percent chance of thunderstorms in the afternoon. Highs in the lower 70s. South winds 10 to 20 mph.
Sunday Night
Mostly cloudy with a 40 percent chance of thunderstorms. Lows in the upper 40s. Enjoy the trip and the family gathering... :)

holtzy
05-14-2004, 10:17 AM
Sweet. Thank you guys so much. Man I must have been tired last night...I know how to do a local connection, but didn't get how to actually pass the var from html to flash. This...var obj=parent.main.admin;
if (obj) obj.SetVariable("_root.myFilename", "this is the filename!");is what I was missing. I should be ok now, and might even give the watch thingy a try. I'm also anxious to see how the DIV stuff works out....thanks again! And have a nice trip petefs!

holtzy
05-15-2004, 01:43 PM
Ok, I am able to pass the variable from php/html to flash, but on button press when the value of the variable changes (it shows the new value on the html screen - see attached) and the flash movie refreshes, it still has the old variable value in the flash movie. I don't get it. Must be something simple I'm missing...

ASphpPassVar = new loadVars();
phpPassVar.load("do_upload.php", phpPassVar, "POST");
phpPassVar.onLoad = VarPassed;

function VarPassed(success) {
if(!success) {
}
else {
if (phpPassVar.CheckedUpload == "completed"){
getURL("javascript:window.open('http://www.google.com','testing7','menubar=no,resizable=y es,toolbar=no,directories=no,location=no,scrollbar s=yes,width=655,height=505'); void(0);");
}
_root.txtTesting.text = phpPassVar.CheckedUpload;
}
}

It wouldn't be browser caching or anything like that would it?

holtzy
05-15-2004, 05:13 PM
Thank the Lord it finally works! I ended up using FlashVars to send the variable to the embedded flash movie like this...

if ($_POST["submit"] == "Upload") {
$CheckedUpload = 'completed';
}else{
$CheckedUpload = 'notdoneyet';
}

and then <OBJECT classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"
codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,0,0"
WIDTH="100" HEIGHT="100" id="onlyforupload" ALIGN="">
<PARAM NAME=movie VALUE="onlyforupload.swf"> <PARAM NAME=FlashVars VALUE="CheckedUpload=<?echo $CheckedUpload ?>"> <PARAM NAME=quality VALUE=high> <PARAM NAME=bgcolor VALUE=#6699FF> <EMBED src="onlyforupload.swf" quality=high bgcolor=#6699FF WIDTH="100" HEIGHT="100" NAME="onlyforupload" ALIGN=""
TYPE="application/x-shockwave-flash" PLUGINSPAGE="http://www.macromedia.com/go/getflashplayer"> FlashVars="CheckedUpload=<?echo $CheckedUpload ?>"> </EMBED>
</OBJECT>Thanks again! still kind of wondering why it didn't work from the last posts method...

CyanBlue
05-15-2004, 10:11 PM
Glad you got it working... Good job... :)