actionscript 3 runtime variables

code, actionscript, flash, flex, php

the key to creating dynamic systems on the web is the ability to send and receive data from one component to the next. flash and flex are no different. there are a lot of cases where you need to send these variables while the application is running, but there are an equal amount of times where the application needs data at run time. passing variables to flash historically has been rather easy, you just query-string data right into the src tag of your flash movie:

    Actionscript 2 code
  1. src="test.swf?passed=hello"

by doing this flash would create a new variable (in this case named passed) when the flash movie is loaded. but with the advent of OOP coding in AS3, this technique has become depreciated.

in actionscript 3 you need to use the flashvars parameter to send data to your flash movie. the technique is the same for both flash and flex, but once the variable is passed flash and flex has a different syntax to access these vars. here is a simple php script that displays a text box, for data input then creates a swf wrapper that embeds your variable into the swf
( look for <?php echo($getit); ?> )

    php code
  1. <html><head><title>flex runtime vars</title>
  2. <?php
  3. $getit = $_REQUEST["what"];
  4. if(!$getit){
  5. ?>
  6. </head><body bgcolor="#000000">
  7. <form method="GET" action="index.php">
  8. <input type="text" id="what" name="what" style="COLOR: #cccccc;BACKGROUND-COLOR:#000000" /><br />
  9. <input type="submit" value="submit" style='COLOR: #cccccc; BACKGROUND-COLOR: #282828' />
  10. </form>
  11. <?php
  12. } else {
  13. ?>
  14. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  15. <link rel="stylesheet" type="text/css" href="deeplinking/deeplinking.css" />
  16. <script src="AC_OETags.js" language="javascript"></script>
  17. <script src="deeplinking/deeplinking.js" language="javascript"></script>
  18. <style>
  19. body { margin: 0px; overflow:hidden }
  20. </style>
  21. <script language="JavaScript" type="text/javascript">
  22. var requiredMajorVersion = 9;
  23. var requiredMinorVersion = 0;
  24. var requiredRevision = 28;
  25. </script>
  26. <body scroll="no" bgcolor="#000000">
  27. <script language="JavaScript" type="text/javascript">
  28. <!--
  29. var hasProductInstall = DetectFlashVer(6, 0, 65);
  30. var hasRequestedVersion = DetectFlashVer(requiredMajorVersion, requiredMinorVersion, requiredRevision);
  31. if ( hasProductInstall && !hasRequestedVersion ) {
  32. var MMPlayerType = (isIE == true) ? "ActiveX" : "PlugIn";
  33. var MMredirectURL = window.location;
  34. document.title = document.title.slice(0, 47) + " - Flash Player Installation";
  35. var MMdoctitle = document.title;
  36. AC_FL_RunContent(
  37. "src", "playerProductInstall",
  38. "FlashVars", "MMredirectURL="+MMredirectURL+'&MMplayerType='+MMPlayerType+'&MMdoctitle='+MMdoctitle+"",
  39. "width", "100%",
  40. "height", "100%",
  41. "align", "middle",
  42. "id", "test",
  43. "quality", "high",
  44. "bgcolor", "#869ca7",
  45. "name", "test",
  46. "allowScriptAccess","sameDomain",
  47. "type", "application/x-shockwave-flash",
  48. "pluginspage", "http://www.adobe.com/go/getflashplayer"
  49. );
  50. } else if (hasRequestedVersion) {
  51. AC_FL_RunContent(
  52. "src", "test",
  53. "width", "100%",
  54. "height", "100%",
  55. "align", "middle",
  56. "id", "test",
  57. "quality", "high",
  58. "bgcolor", "#869ca7",
  59. "name", "test",
  60. "allowScriptAccess","sameDomain",
  61. "type", "application/x-shockwave-flash",
  62. "flashvars",'passed=<?php echo($getit); ?>',
  63. "pluginspage", "http://www.adobe.com/go/getflashplayer"
  64. );
  65. } else {
  66. var alternateContent = 'Alternate HTML content should be placed here. '
  67. + 'This content requires the Adobe Flash Player. '
  68. + '<a href=http://www.adobe.com/go/getflash/>Get Flash</a>';
  69. document.write(alternateContent);
  70. }
  71. // -->
  72. </script>
  73. <noscript>
  74. <object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"
  75. id="test" width="100%" height="100%"
  76. codebase="http://fpdownload.macromedia.com/get/flashplayer/current/swflash.cab">
  77. <param name="movie" value="test.swf" />
  78. <param name="quality" value="high" />
  79. <param name="bgcolor" value="#869ca7" />
  80. <param name="flashvars" value="passed=<?php echo($getit); ?>" />
  81. <param name="allowScriptAccess" value="sameDomain" />
  82. <embed src="test.swf" quality="high" bgcolor="#869ca7"
  83. width="100%" height="100%" name="test" align="middle"
  84. flashvars="passed=<?php echo($getit); ?>"
  85. play="true"
  86. loop="false"
  87. quality="high"
  88. allowScriptAccess="sameDomain"
  89. type="application/x-shockwave-flash"
  90. pluginspage="http://www.adobe.com/go/getflashplayer">
  91. </embed>
  92. </object>
  93. </noscript>
  94. <?php
  95. }
  96. ?>
  97. </body></html>

to access the "passed" var is flex use:
Application.application.parameters.passed;
    mxml and actionscript 3 code
  1. <?xml version="1.0" encoding="utf-8"?>
  2. <mx:Application
  3. xmlns:mx="http://www.adobe.com/2006/mxml"
  4. layout="absolute"
  5. backgroundGradientAlphas="[1.0, 1.0]"
  6. backgroundGradientColors="[#000000, #252525]"
  7. creationComplete="init()">
  8. <mx:Script>
  9. <![CDATA[
  10. public var passedvar:String;
  11. private function init():void {
  12. //passed is the name of the flash var
  13. passedvar = Application.application.parameters.passed;
  14. thething.htmlText = passedvar.toString();
  15. }
  16. ]]>
  17. </mx:Script>
  18. <mx:Label id="thething" text="Label" color="#FFFFFF" fontSize="23" horizontalCenter="0" verticalCenter="0" />
  19. </mx:Application>

to access the "passed" var is flash use:
LoaderInfo(this.root.loaderInfo).parameters;
    flash actionscript 3 code
  1. var tf:TextField = new TextField();
  2. tf.textColor = 0xFFFFFF;
  3. addChild(tf);
  4. try {
  5. var paramObj:Object = LoaderInfo(this.root.loaderInfo).parameters;
  6. //passed is the name of the flash var
  7. tf.appendText("passed var: " + paramObj['passed'].toString());
  8. } catch (error:Error) {
  9. tf.appendText("error: " + error.toString());
  10. }
view the flex demo here
view the flash demo here

RFC822 compliant dates for rss feeds

code, dotnet, php, work, C#

with the advent of web-syndication, a few different feed protocols have evolved (rss and atom being the most popular). because of their growth in popularity the protocol to create a feed has become more stringent. luckily we have validators who help us keep our feeds on the right track. one of these guidelines is RFC822 compliant dates. these dates look like Sat, 14 Jul 2007 18:40:26 -0400. formatting your data to be compliant with this standard can be challenging, so i have written some code to help you along...

Creating a RFC822 compliant date in php is a snap...

    php code
  1. $rssDate = date("r");


in asp.net this is a bit more tricky. microsoft doesn't have a native RFC822 date format, so we are going to have to convert our dateTime.now() into that format
    asp.net C#
  1. public string dateFormat(DateTime date)
  2. {
  3. int offset = TimeZone.CurrentTimeZone.GetUtcOffset(DateTime.Now).Hours;
  4. string timeZone = "+" + offset.ToString().PadLeft(2, '0');
  5. if (offset < 0)
  6. {
  7. int i = offset * -1;
  8. timeZone = "-" + i.ToString().PadLeft(2, '0');
  9. }
  10. return date.ToString("ddd, dd MMM yyy HH:mm:ss " + timeZone.PadRight(5, '0'));
  11. }
  12.  

pure php email validation

code, php

    php code
  1. <?php
  2. if (!eregi("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$", $from)) {
  3. header("Location: http://error.php");
  4. } else {
  5. header("Location: http://thanx.php");
  6. }
  7. ?>

MMVII .( xero harrison ) . http://the.fontvir.us/b10g
RSS syndication