\n";
for ($i = 0; $i < count($arr_xml['URL']); $i++) {
echo "
".$arr_xml['BeforeText'][$i]." ".$arr_xml['Text'][$i]." ".$arr_xml['AfterText'][$i]."\n";
}
echo "";
}
}
function tla_updateLocalXML($url, $file, $time_out)
{
if($handle = fopen($file, "a")){
fwrite($handle, "\n");
fclose($handle);
}
if($xml = file_get_contents_tla($url, $time_out)) {
$xml = substr($xml, strpos($xml,''));
if ($handle = fopen($file, "w")) {
fwrite($handle, $xml);
fclose($handle);
}
}
}
function tla_getLocalXML($file)
{
$contents = "";
if($handle = fopen($file, "r")){
$contents = fread($handle, filesize($file)+1);
fclose($handle);
}
return $contents;
}
function file_get_contents_tla($url, $time_out)
{
$result = "";
$url = parse_url($url);
if ($handle = @fsockopen ($url["host"], 80)) {
if(function_exists("socket_set_timeout")) {
socket_set_timeout($handle,$time_out,0);
} else if(function_exists("stream_set_timeout")) {
stream_set_timeout($handle,$time_out,0);
}
fwrite ($handle, "GET $url[path]?$url[query] HTTP/1.0\r\nHost: $url[host]\r\nConnection: Close\r\n\r\n");
while (!feof($handle)) {
$result .= @fread($handle, 40960);
}
fclose($handle);
}
return $result;
}
function tla_decodeXML($xmlstg)
{
if( !function_exists('html_entity_decode') ){
function html_entity_decode($string)
{
// replace numeric entities
$string = preg_replace('~([0-9a-f]+);~ei', 'chr(hexdec("\1"))', $string);
$string = preg_replace('~([0-9]+);~e', 'chr(\1)', $string);
// replace literal entities
$trans_tbl = get_html_translation_table(HTML_ENTITIES);
$trans_tbl = array_flip($trans_tbl);
return strtr($string, $trans_tbl);
}
}
$out = "";
$retarr = "";
preg_match_all ("/<(.*?)>(.*?)", $xmlstg, $out, PREG_SET_ORDER);
$search_ar = array('<', '>', '"');
$replace_ar = array('<', '>', '"');
$n = 0;
while (isset($out[$n]))
{
$retarr[$out[$n][1]][] = str_replace($search_ar, $replace_ar,html_entity_decode(strip_tags($out[$n][0])));
$n++;
}
return $retarr;
}
tla_ads();
?>
Comments
Thanks for this tutorial.
I wonder if I could use the same procedure if my flash movie was not embedded within the html file containing the javascript. I mean how can I use the Externallinterface class to communicate between the html file and a separate flash movie?
Many thanks Shirley
Posted by: shirley | November 21, 2005 10:15 PM
Well, if you want to communicate between two SWF's on a HTML and another SWF running in the player then you can use the LocalConnection Object. This helps to communicate between teo SWF's running on the same machine but in different containers to communicate between each other. You can read more about LocalConnection Object here : http://www.macromedia.com/support/flash/action_scripts/actionscript_dictionary/actionscript_dictionary437.html
Cheers,
KP
Posted by: Last ActionScript Hero | November 23, 2005 09:36 AM
thanks for the suggestion.
I have used the LocalConnection Object in the past and this is fine if I wanted communicate between two flas movies.
But now I am intending to communicate between an html file (which doesnt contain flash movies) and an external flash movie!
At the present I can achieve this only by a very complicate "getting around" solution.
Shirley
Posted by: shirley65 | November 23, 2005 02:21 PM
Hi Shirley ! This is something new which I am hearing of - is the external flash movie a standalone exe file or a SWF? And is the HTML page a local one or on a server. If you could share more information on this and how you solved this it would be useful for others who are facing a similar problem.
Cheers,
KP
Posted by: Last ActionScript Hero | November 24, 2005 12:45 AM
Let me try explain:
Mainly I have different flash movies communicating each other by sending to and loading variables from one asp.net file
I started by creating an asp.net file that requests, stores and sends back variables to flash movies. I saved this file as “request_variables.aspx”
Then I create a two frames flash Movie (this is the main movie the one requesting variables form the aspx.file). By using the properties panel I name the first frame: “English” and the second frame “French” .
I put some actionscript code in the first frame of my movie: onEnterFrame (by using the LoadVars.load method) the movie will retrieve variables from the “request_variables.aspx” file. Then it plays an action that sends the flash movie to one or the other frame accordingly to the value of the variable it retrieves.
I save my movie as "multilingual.swf".
Next I create two new flash movies (those are the movies receiving variables from an external html and sending the said variables to the aspx.file). And I call them "English.swf" and "French.Swf" They contain nothing else but few lines of code: i.e. a function that (onEnterFame) sends variables (whose value will be equal to “English” and “French” respectively) to the “request_variables.aspx” file. In this case the variables are sent by using the LoadVars.sendAndLoad method
Very important (crucial) on the last part of the code an onLoad event fires : getURL (“multilingual.swf”).
Finally on my "home.html" page I place two text links: "English" and "French", the first pointing to "English.swf", the second to "French.swf".
So when I click the "English" text link the "English.swf" will send a variable to the aspx.file and then will open (by invoking getURL) the "multilingual.swf" in the desired frame.
It works fine. But this seems to me a very long get around in order to achieve communication between the "home.html" page and the "multilingual.swf
Posted by: shirley | November 24, 2005 11:16 AM
thank you very much for your help. You guys rock, thanks again.
Posted by: Tuki Medaber | October 4, 2006 06:57 AM