Groups | Blog | Home
all groups > flash actionscript > september 2007 >

flash actionscript : Passing Variables to ActionScript CS3 from JavaScript


SpectacularStuff
9/21/2007 11:47:09 PM
Hello,

I cannot seem to figure out what I am doing wrong and I need some help
:confused;. Who better to ask than the experts right?

I have everything working correctly thus far except for this actionscript. I
am using Flash CS3 with ActionScript CS3.

I have 5 buttons made up in flash.
I am attempting to do the following tasks
1. Make buttons with effects in flash - done
2. Put the correct button in the down position based upon the webpage that the
user is on.
In order to perform this dynamically I apparently have to use 3 different
languages, PHP, JavaScript, ActionScript.

I have been messing with this for a week and cannot figure it out. I have all
of the rest of the scripts tested and verified working.

Here is the link to my test page
http://www.spectacularstuff.com/php-test/inprogress/php-url-detection.php

Here is all of my code for testing. (This doesn't include any buttons. This
is just merely to test to see if I am passing variables.)

[b]PHP Code[/b] to detect the filename.
<?php
function curPageName() {
return substr($_SERVER["SCRIPT_NAME"],strrpos($_SERVER["SCRIPT_NAME"],"/")+1);
}
echo "The current page name detected by PHP is ".curPageName();
?>

[b]JavaScript Code[/b] to pass the variables to Flash
<script language="javascript" src="swfobject.js">
var so = new SWFObject("php-url-detection.swf", "php-url-detection", "550",
"400", "9", "#FFFFFF");
so.AddVariable("currentpage","<?php echo curPageName(); ?>")
</script>

[b]ActionScript Code[/b] to get Variables from JavaScript and display them in
flash.
// Dynamically Create Text Fields
var tf:TextField = new TextField();
tf.autoSize = TextFieldAutoSize.LEFT;
tf.border = false;
addChild(tf);

var tf2:TextField = new TextField();
tf2.autoSize = TextFieldAutoSize.LEFT;
tf2.border = false;
addChild(tf2);

//Create variable to write to page
var myStr2:String;

//first attempt at putting the variable onto the page.
//This LoaderInfo has to be capitlized. An error occurs if not.
var paramObj:Object = LoaderInfo(this.root.loaderInfo).parameters.currentpage;

//second attempt at putting the variable onto the page
var myStr:String = this.root.loaderInfo.parameters.currentpage;
trace (paramObj);
trace (myStr);

if (myStr == null)
{
myStr = "Flash is not reading the variables from JavaScript. :(";
myStr2 = " ";
}
else
myStr2 = "Flash is reading the variables from JavaScript!! :)"

tf.text = myStr; //Display the URL onto the page
tf2.text = myStr2 //Display Flash is happy

[-- End of Code --]


Please help.

Thank you in advance.

Wayne
SpectacularStuff
9/23/2007 10:37:12 PM
I really could use some help from anyone that can see what I am doing incorrectly.

Any help is appeciated.

Thanks,

SpectacularStuff
9/29/2007 3:51:44 AM
I found an answer to this for anyone that is looking for an answer. I have it written the answer in a different forum:
AddThis Social Bookmark Button