{"id":626,"date":"2010-02-01T20:21:56","date_gmt":"2010-02-01T20:21:56","guid":{"rendered":"http:\/\/www.codingfriends.com\/?p=626"},"modified":"2010-02-01T20:24:08","modified_gmt":"2010-02-01T20:24:08","slug":"hello-world-8","status":"publish","type":"post","link":"https:\/\/www.codingfriends.com\/index.php\/2010\/02\/01\/hello-world-8\/","title":{"rendered":"Hello World"},"content":{"rendered":"<p>Flex is the Flash SDK from Adobe, you can download a open source command line compiler from adobe (<a href=\"http:\/\/www.adobe.com\/products\/flex\/\">Flex open source page<\/a> ).   The Free SDK link is <a href=\"http:\/\/www.adobe.com\/cfusion\/entitlement\/index.cfm?e=flex3sdk\">here<\/a>.<\/p>\n<p>Once you have downloaded the free SDK, you will need to place into the system. I have placed mine into \/opt directory called flex_sdk_3, so something like (you will need to be root to do this!)<\/p>\n<pre lang=\"bash\">\r\ncd \/opt\r\nmkdir flex_sdk_3\r\ncd flex_sdk_3\r\nunzip <place where your free sdk is)\r\n<\/pre>\n<p>and then create a place for where you are going to be creating your flex scripts, I placed mine into my home directory under my programming\/flex sturcture, so this is where I am<\/p>\n<pre lang=\"bash\">\r\nmkdir -p ~\/Programming\/flex\/\r\n<\/pre>\n<p>The -p will create any directories that are not present there already, and also the ~ is for the home directory that user.<\/p>\n<p>I then copied the flex-config.xml from the \/opt\/flex_sdk_3\/frameworks directory into the Programming\/flex directory and edited it to the new values.<br \/>\nThe full differences between the standard flex-config.xml and the one that I have altered is below, but basically I have added into the xml elements values the new directory for where flex-sdk is (e.g. \/opt\/flex_sdk_3\/) so that flex's command line environment will know where to get the libraries to compile and create the swf (ShockWave Flash), but here are the elements that I have altered.<\/p>\n<pre lang=\"xml\">\r\n<external-library-path>\r\n     <path-element>\/opt\/flex_sdk_3\/frameworks \r\n<library-path>\r\n     all the <path-element's>\/opt\/flex_sdk_3\/frameworks\r\n<namespaces>\r\n   the <manifest>\/opt\/flex_sdk_3\/frameworks path to the framework directory file.\r\n<\/pre>\n<p>Because the class structure follows the directory structure of the directories below the compiling environment, I created the following directory structure com\/codingfriends\/helloworld with<\/p>\n<pre lang=\"bash\">\r\nmkdir -p com\/codingfriends\/helloworld\r\n<\/pre>\n<p>which will create the whole structure if there is no directories there already.<\/p>\n<p>Then you can place these two files into the helloworld directory<\/p>\n<p>This is the class Greeter that is created and turned into a object within the swf file save this as Greeter.as<\/p>\n<pre lang=\"cpp\">\r\n\/\/ the directory structure of where the class is.\r\npackage com.codingfriends.helloworld\r\n{\r\n\tpublic class Greeter\r\n\t{\r\n\t\tprivate var name:String;\r\n\t\t\r\n\t\t\/\/ constructor\r\n\t\tpublic function Greeter(initialName:String=\"Ian\")\r\n\t\t{\r\n\t\t\tname = initialName;\r\n\t\t}\r\n\r\n\t\t\/\/ sayHello returns a String\r\n\t\tpublic function sayHello():String\r\n\t\t{\r\n\t\t\tvar result:String;\r\n\t\t\t\/\/ if the class private name is present\r\n\t\t\tif (name!=null && name.length >0)\t\r\n\t\t\t{\r\n\t\t\t\tresult = \"Hello there, \"+name+\".\";\r\n\t\t\t}\r\n\t\t\t\/\/ should never reach here on a basic run.\r\n\t\t\telse \r\n\t\t\t{\r\n\t\t\t\tresult=\"Hello there.\";\r\n\t\t\t}\r\n\t\r\n\t\t\treturn result;\r\n\t\t}\r\n\t}\r\n}\r\n<\/pre>\n<p>var = variable and the type of variable or return variable is at the end of the definition e.g. <\/p>\n<pre lang=\"cpp\">\r\npublic var name:String; \/\/ this is a variable named \"name\" and it is of type String\r\npublic function sayHello():String \/\/ this is a function named \"sayHello\" and returns a String type\r\n<\/pre>\n<p>save this as Greeter_mx.mxml<\/p>\n<pre lang=\"xml\">\r\n<?xml version=\"1.0\" encoding=\"utf-8\"?>\r\n<mx:Application xmlns:mx=\"http:\/\/www.adobe.com\/2006\/mxml\" layout=\"absolute\" initialize=\"initApp();\">\r\n<mx:Script>\r\n<![CDATA[\r\nimport com.codingfriends.helloworld.Greeter;\r\n\/\/ the initialize application .. the start\r\nprivate function initApp():void\r\n{\r\n\t\/\/ create a new Greeter object with no passing in name\r\n\tvar myGreeter:Greeter = new Greeter();\r\n\t\/\/ and say hello world \r\n\toutput.text+=myGreeter.sayHello();\r\n\t\/\/ create a new greeter with the name = genux instead\r\n\tvar newGreeter:Greeter = new Greeter(\"genux\");\r\n\toutput.text+=newGreeter.sayHello();\r\n}\r\n]]>\r\n<\/mx:Script>\r\n\r\n<mx:Text id=\"output\" width=\"100%\" textAlign=\"center\"\/>\r\n<\/mx:Application>\r\n<\/pre>\n<p>The <mx:Script> is the place where the code starts, the rest is just the adobe application settings, within the code there is a reference to \"output\", which is defined in the <mx:Text xml element for the application code.  The code will create a new Greeter class from the Greeter.as file above and then add the output from the sayHello() function to the output mx:Text element.\n\nWhen you want to compile up the source code, you will need to add the \/opt\/flex_sdk_3\/bin (which is where the mxmlc command line compiler for creating the swf file) to the console\n\n\n<pre lang=\"bash\">\r\nPATH=$PATH:\/opt\/flex_sdk_3\/bin\r\n<\/pre>\n<p>and then to compile up the source code<\/p>\n<pre lang=\"bash\">\r\nmxmlc -load-config flex-config.xml -source-path=~\/Programming\/flex\/actionscript\/ .\/com\/codingfriends\/helloworld\/Greeter_mx.mxml -output .\/bin\/Greeter_mx.swf\r\n<\/pre>\n<p>the -load-config will load the one in the present directory which I altered, and -source-path is there so that the base directory is used for compiling so the compiler will know where to get the com\/codingfriends\/helloworld\/Greeter.as and Greeter_mx.mxml, and the -output is what the output flash file is\/placed.<\/p>\n<p>Here is the output of the Greeter.swf file.<\/p>\n<p><embed src=\"\/swf\/Greeter_mx.swf\" width=\"250\" height=\"50\"><br \/>\n<\/embed><\/p>\n<p>Here is the difference (diff) between the flex-config.xml from the one that I edited and the one that was in the \/opt\/flex_sdk_3\/frameworks directory.<\/p>\n<pre lang=\"bash\">\r\n53c53\r\n<           <path-element>\/opt\/flex_sdk_3\/frameworks\/libs\/player\/{targetPlayerMajorVersion}\/playerglobal.swc<\/path-element>\r\n---\r\n>           <path-element>libs\/player\/{targetPlayerMajorVersion}\/playerglobal.swc<\/path-element>\r\n70c70\r\n<          <path-element>\/opt\/flex_sdk_3\/frameworks\/libs<\/path-element>\r\n---\r\n>          <path-element>libs<\/path-element>\r\n72,74c72,74\r\n<          <path-element>\/opt\/flex_sdk_3\/frameworks\/libs\/player<\/path-element>\r\n<          <path-element>\/opt\/flex_sdk_3\/frameworks\/libs\/player\/{targetPlayerMajorVersion}<\/path-element>\r\n<            <path-element>\/opt\/flex_sdk_3\/frameworks\/locale\/{locale}<\/path-element>\r\n---\r\n>          <path-element>libs\/player<\/path-element>\r\n>          <path-element>libs\/player\/{targetPlayerMajorVersion}<\/path-element>\r\n>            <path-element>locale\/{locale}<\/path-element>\r\n82c82\r\n<             <manifest>\/opt\/flex_sdk_3\/frameworks\/mxml-manifest.xml<\/manifest>\r\n---\r\n>             <manifest>mxml-manifest.xml<\/manifest>\r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Flex is the Flash SDK from Adobe, you can download a open source command line compiler from adobe (Flex open source page ). The Free SDK link is here. Once you have downloaded the free SDK, you will need to place into the system. I have placed mine into \/opt directory called flex_sdk_3, so something &hellip; <a href=\"https:\/\/www.codingfriends.com\/index.php\/2010\/02\/01\/hello-world-8\/\" class=\"more-link\">Continue reading <span class=\"screen-reader-text\">Hello World<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[79],"tags":[74,81,83,80],"class_list":["post-626","post","type-post","status-publish","format-standard","hentry","category-flex-flash","tag-flash","tag-flex","tag-mxmlc","tag-swf"],"_links":{"self":[{"href":"https:\/\/www.codingfriends.com\/index.php\/wp-json\/wp\/v2\/posts\/626","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.codingfriends.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.codingfriends.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.codingfriends.com\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.codingfriends.com\/index.php\/wp-json\/wp\/v2\/comments?post=626"}],"version-history":[{"count":5,"href":"https:\/\/www.codingfriends.com\/index.php\/wp-json\/wp\/v2\/posts\/626\/revisions"}],"predecessor-version":[{"id":631,"href":"https:\/\/www.codingfriends.com\/index.php\/wp-json\/wp\/v2\/posts\/626\/revisions\/631"}],"wp:attachment":[{"href":"https:\/\/www.codingfriends.com\/index.php\/wp-json\/wp\/v2\/media?parent=626"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.codingfriends.com\/index.php\/wp-json\/wp\/v2\/categories?post=626"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.codingfriends.com\/index.php\/wp-json\/wp\/v2\/tags?post=626"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}