-
I have attempted to use the urlencode function within PHP to encode the filename and have sadly found out that it does not encode the "-" which is what is giving me issues on this particular problem.
If I do not use a dash then everything turns out fine however if I want to use a - within the URL than ActionScript cannot read it because it is not URL encoded. I attempted a str_replace function however it keeps screwing up.
I will come back with the answer on how I repaired this however I believe that this goes beyond the AS3 discussion.
Thanks again for your help.
Wayne
-
Well,
I have bad news to report. I now have the whole name URLEncoded including the dash and the period and I still receive that error. This leaves me in belief that AS3 cannot handle dashes in the URL. This is unfortunate as it puts a huge damper search engine optimization with user-friendly URL's.
Wayne
-
Spec, Look into swfaddress. As for the - in the file names the issue there is that outside of a string - is minus. Somehow something you did is not in a string and is trying to actually call a function.
-
Okay, damn it..... I used my code without the dash and it still came back with the same damn issue. It is the following code that causes that issue. I am presuming that I have to include the variable name in that code.
I am going to add -->'FlashVars', 'currentpage',<-- to there (without the arrows) and that should solve the issue.
Yes, that solved the issue. On the next thread I will fully explain what my new found Internet friend, MyFriendIsATaco (name is friggin hilarious), and I have went through in order to get this to read. What I did anyway.
Wayne
Code:
<script language="javascript">
if (AC_FL_RunContent == 0) {
alert("This page requires AC_RunActiveContent.js.");
} else {
AC_FL_RunContent(
'codebase', 'http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,0,0',
'width', '550',
'height', '400',
'src', 'filename-detection',
'quality', 'high',
'pluginspage', 'http://www.macromedia.com/go/getflashplayer',
'align', 'middle',
'play', 'true',
'loop', 'true',
'scale', 'showall',
'wmode', 'window',
'devicefont', 'false',
'id', 'filename-detection',
'bgcolor', '#ffffff',
'name', 'filename-detection',
'menu', 'true',
'allowFullScreen', 'false',
'allowScriptAccess','sameDomain',
'movie', 'filename-detection',
'salign', ''
); //end AC code
}
</script>
-
Alright, apparently you are doing something severely wrong, because I just threw this together in 5 minutes: http://testbed.ydekproductions.com/p...ion/index.html
It works. The code I used in my flash file is this:
Code:
urlTxt.text = root.loaderInfo.parameters.url;
and this is the html:
Code:
<html>
<head>
<title>test</title>
<script type="text/javascript" src="swfobject.js"></script>
</head>
<body>
<div id="main" style="width:550px; height:400px;"></div>
<script type="text/javascript">
var so=new SWFObject('movie.swf', 'main_swf', '550', '400', '9', '#FFFFFF');
so.addVariable('url', window.location.href)
so.write('main');
</script>
</body>
</html>
you need the swfobject.js file for that to work. grab it here: http://testbed.ydekproductions.com/p...n/swfobject.js
-
I figured the issue out. When you export the main HTML file from Flash you end up the above JavaScript code in your HTML. If you keep that code within your HTML document than you have to modify it in order for that to work properly.
Look at the last line of the code. I had to add that in order for it to work properly
Code:
<script language="javascript">
if (AC_FL_RunContent == 0) {
alert("This page requires AC_RunActiveContent.js.");
} else {
AC_FL_RunContent(
'codebase', 'http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,0,0',
'width', '550',
'height', '400',
'src', 'filename-detection',
'quality', 'high',
'pluginspage', 'http://www.macromedia.com/go/getflashplayer',
'align', 'middle',
'play', 'true',
'loop', 'true',
'scale', 'showall',
'wmode', 'window',
'devicefont', 'false',
'id', 'filename-detection',
'bgcolor', '#ffffff',
'name', 'filename-detection',
'menu', 'true',
'allowFullScreen', 'false',
'allowScriptAccess','sameDomain',
'movie', 'filename-detection',
'salign', '',
'FlashVars', 'currentpage' //I had to add this in order for it to work.
); //end AC code
}
</script>
My biggest question is the following:
I know that I can use the DIV id=main and the so.write('main') method of writing to the screen however I should be able to use AS3 to write as well.
Obviously, by writing out to the screen using the method just mentioned we can prove that the variable was passed to AS3.
The question at this point becomes, if the variable is being passed to AS3 then we should be able to use AS3 to write it to the main stage and not have to rely on the div id and JavaScript.
I should be able to write out the following:
Code:
var tf:TextField = new TextField();
tf.text = root.loaderInfo.parameters.currentpage;
addChild(tf);
//This should write out to the main stage with whatever is contained in currentpage however this is not happening.
//OR
var myStr:String = root.loaderInfo.parameters.currentpage;
var textfield:TextField = new TextField();
textfield.text = myStr;
textfield.x = 100;
textfield.y = 100;
addChild(textfield);
//This should write out to the main stage with whatever is contained in currentpage however this is not happening.
What am I doing wrong that those are not writing out to the screen using AS3. I can write normal text out to the screen using that same method. Am I missing something?
If I type in
Code:
var tf:TextField = new TextField();
tf.text = "Hello World";
addChild(tf);
//This writes Hello World out using the main stage.
I know it is reading the variables as with
http://www.spectacularstuff.com/php-...-detection.php. I just am dumbfounded as to why it will not output that variable to the stage using AS3 instead of the DIV ID method:confused: :confused:
Wayne
-
your problem in that case is not with AS3. The problem is that the flash movie is not being displayed on the page.
The method that you are describing, the AC_FL_RunContent thing is what Flash auto generates for you. My method, SWFObject is a similar process, just different. It is what I prefer for different personal reasons, but they both achieve the same thing. I was giving you examples with the SWFObject way. I think that is what was confusing you. In SWFObject, if you leave out so.write('main');, your swf file will never be embedded on the screen, that is a must. It has nothing to do with the actionscript in the file. The file isn't even being shown.
You shouldn't use both methods for the same thing, it won't work, like what you are attempting to do on your test page.
-
Okay.... now that makes sense. That is what was confusing me.
So, if I understand this correctly then. There are two very different methods available for sending variables to Flash.
There is the SWFObject method and there is the AC_FL_RunContent method.
The SWFObject method requires you to use the div id=main way of displaying flash onto the pages.
The AC_FL_RunContent way requires you to use FlashVars in order to pass data to the SWF file.
Is this correct?
Thanks,
Wayne
-
not quite. SWFObject and AC_FL_RunContent are both ways to embed a swf file on your website, as well as the old school <object> and <embed> tags.
They both work differently and both support FlashVars.. in different ways. SWFObject uses the addVariable() method, and AC_FL_RunContent does it their own way.
You need to use one of those methods even if you are not passing variables to the swf file.
-
Hey,
I know it doesn't do much but I want to thank you very much for all of the time and effort you have spent with me here over the last week or two. I now know that there are two different ways to accomplish this and know exactly what needs to be changed for both of those to work separately.
I can now pass data from a webpage to a flash movie without an issue. I did it with your code and worked with flashvars to get that to work.
http://www.spectacularstuff.com/php-.../flashvars.php
Both ways are pretty simple if you know what you are doing. If you don't, it is just amazing how something so damn simple can be so damn difficult... lol
Thanks,
My last post will be exactly what has to be done in order to get these to work in both methods for other people reading this and then we can mark this as resolved (although I am not sure how to do that).
Wayne
-
Hey everyone, here is everything from all of these posts all rolled up into one post.
Passing Variables to Flash from a webpage
I am working with AS3 and Flash CS3. There are three ways (that I know of) to pass variables from a webpage to AS3. I will only be discussing two of those ways here as discussed within this thread.
FlashVars
FlashVars are very simple to implement and a little harder to extract.
You need to add HTML to your webpage to send the FlashVars and AS3 Scripting to detect the Flash Vars.
Depending on how you are using your HTML the FlashVars have to be put in 3 separate areas on the page.
For this example I am using AC_FL_RunContent to embed flash into a PHP/HTML page. Everything is HTML the page extension is merely PHP.
Step 1
Add the following code to AC_FL_RunContent.
'FlashVars', 'variable value here',
Your code will look like the following:
Code:
<script language="javascript">
if (AC_FL_RunContent == 0) {
alert("This page requires AC_RunActiveContent.js.");
} else {
AC_FL_RunContent(
'codebase', 'http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,0,0',
'width', '550',
'height', '400',
'src', 'flashvars',
'quality', 'high',
'pluginspage', 'http://www.macromedia.com/go/getflashplayer',
'align', 'middle',
'play', 'true',
'loop', 'true',
'scale', 'showall',
'wmode', 'window',
'devicefont', 'false',
'id', 'flashvars',
'bgcolor', '#ffffff',
'name', 'flashvars',
'menu', 'true',
'allowFullScreen', 'false',
'allowScriptAccess','sameDomain',
'movie', 'flashvars',
'FlashVars', 'FlashVariableHere',
'salign', ''
); //end AC code
}
</script>
Step 2 & 3
Add your FlashVars to your to your parameters and your embed tag.
Add the following parameter inside your object tag:
<param name="FlashVars" value="FlashVariableNameHere=VariableValueHere" />
Your code will look like the following:
Code:
<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,0,0" width="550" height="400" id="flashvars" align="middle">
<param name="allowScriptAccess" value="sameDomain" />
<param name="allowFullScreen" value="false" />
<param name="movie" value="flashvars.swf" />
<param name="quality" value="high" />
<param name="bgcolor" value="#ffffff" />
<param name="FlashVars" value="FlashVariableNameHere=VariableValueHere" />
<embed src="flashvars.swf" flashvars="FlashVariableNameHere=VariableValueHere" quality="high" bgcolor="#ffffff" width="550" height="400" name="flashvars" align="middle" allowScriptAccess="sameDomain" allowFullScreen="false" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" />
</object>
Lastly, you have to add the AS3 code in the 1st frame of the main timeline.
This code retrieves the variable and displays it on the page.
Code:
// AS3
var tf:TextField = new TextField();
tf.autoSize = TextFieldAutoSize.LEFT;
tf.border = true;
addChild(tf);
tf.appendText("params:" + "\n");
try {
var keyStr:String;
var valueStr:String;
var paramObj:Object = LoaderInfo(this.root.loaderInfo).parameters;
for (keyStr in paramObj) {
valueStr = String(paramObj[keyStr]);
tf.appendText("\t" + keyStr + ":\t" + valueStr + "\n");
}
}
catch (error:Error) {
// tf.appendText(error); //This code is commented out. According to Adobe, it is supposed to be here however it causes Error 1067: Implicit coercion of a value of type Error to an unrelated type String when it is active.
}
=====================================
Sending Variables with SWFObject
There are only two items that you need for this.
1. Do not use the AC_FL_RunContent to embed your flash content (for this example).
Use the SWFObject to embed your flash.
You will need the following items.
SWFObject.js
http://blog.deconcept.com/swfobject/swfobject.zip
http://blog.deconcept.com/swfobject/
Add this code in between the <head> </head> HTML tags.
Code:
<script type="text/javascript" src="swfobject.js"></script>
Add the following code in between the <body></body> HTML tags.
Code:
<div id="main" style="width:550px; height:400px;"></div>
<script type="text/javascript">
var so=new SWFObject('SwfFileNameHere.swf', 'SwfFileNameHere_swf', '550', '400', '9', '#FFFFFF');
so.addVariable('FlashVariable2NameHere', 'FlashVariableValueHere')
so.write('main');
</script>
Include the following code into the first frame on the main stage of your flash file.
Code:
// AS3
var FlashVariable1NameHere:TextField = new TextField();
FlashVariable1NameHere.text = root.loaderInfo.parameters.FlashVariable2NameHere;
addChild(FlashVariable1NameHere);
SWFObject Real World Example
Code:
<!-- HTML/JavaScript //-->
<html>
<head>
<title>test</title>
<script type="text/javascript" src="swfobject.js"></script>
</head>
<body>
<div id="main" style="width:100%; height:100%;"></div>
<script type="text/javascript">
var so=new SWFObject('filename-detection.swf', 'filename-detection_swf', '100%', '100%', '9', '#FFFFFF');
so.addVariable('currentpage', 'fd.php')
so.write('main');
</script>
</body>
</html>
//AS3 Script
var tf:TextField = new TextField();
tf.text = root.loaderInfo.parameters.currentpage;
addChild(tf);
AC_FL_RunContent Real World Example
Code:
<!-- HTML/JavaScript //-->
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>flashvars</title>
<script language="javascript">AC_FL_RunContent = 0;</script>
<script src="AC_RunActiveContent.js" language="javascript"></script>
</head>
<body bgcolor="#ffffff">
<!--url's used in the movie-->
<!--text used in the movie-->
<!-- saved from url=(0013)about:internet -->
<script language="javascript">
if (AC_FL_RunContent == 0) {
alert("This page requires AC_RunActiveContent.js.");
} else {
AC_FL_RunContent(
'codebase', 'http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,0,0',
'width', '550',
'height', '400',
'src', 'flashvars',
'quality', 'high',
'pluginspage', 'http://www.macromedia.com/go/getflashplayer',
'align', 'middle',
'play', 'true',
'loop', 'true',
'scale', 'showall',
'wmode', 'window',
'devicefont', 'false',
'id', 'flashvars',
'bgcolor', '#ffffff',
'name', 'flashvars',
'menu', 'true',
'allowFullScreen', 'false',
'allowScriptAccess','sameDomain',
'movie', 'flashvars',
'FlashVars', 'flashvars.php',
'salign', ''
); //end AC code
}
</script>
<noscript>
<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,0,0" width="550" height="400" id="flashvars" align="middle">
<param name="allowScriptAccess" value="sameDomain" />
<param name="allowFullScreen" value="false" />
<param name="movie" value="flashvars.swf" />
<param name="quality" value="high" />
<param name="bgcolor" value="#ffffff" />
<param name="FlashVars" value="currentpage=flashvars.php" />
<embed src="flashvars.swf" flashvars="currentpage=flashvars.php" quality="high" bgcolor="#ffffff" width="550" height="400" name="flashvars" align="middle" allowScriptAccess="sameDomain" allowFullScreen="false" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" />
</object>
</noscript>
</body>
</html>
// AS3 Script
var tf:TextField = new TextField();
tf.autoSize = TextFieldAutoSize.LEFT;
tf.border = true;
addChild(tf);
tf.appendText("params:" + "\n");
try {
var keyStr:String;
var valueStr:String;
var paramObj:Object = LoaderInfo(this.root.loaderInfo).parameters;
for (keyStr in paramObj) {
valueStr = String(paramObj[keyStr]);
tf.appendText("\t" + keyStr + ":\t" + valueStr + "\n");
}
} catch (error:Error) {
// tf.appendText(error);
}