Compiling Flex apps with external swc libs and RSLs using ruby and rake

Posted by Tim Connor Sat, 08 Aug 2009 21:40:00 GMT

At work I maintain a number of flex projects, some of which are dynamically modified based on the results of slicing up SVG maps. As such, it is far easier to have a rake task do the compiling, rather than recompiling each one by hand, in Flex Builder.

Since there are a range of different projects that share some library code, I had to figure out how to compile them against an external swc, ideally loaded as an RSL for space savings and a couple other benefits. I hadn’t seen many full fleshed out examples of this, so I thought I should share.

Below is a stripped down version of the code that is called from rake; I cut out stuff specific to the work projects. I also made a flex ruby compiler gist so that it can be found on github and modified there.

module FlexCompiler
  COMPILER = "/Applications/Adobe\\ Flex\\ Builder\\ 3/sdks/3.2.0/bin/mxmlc"
  FRAMEWORK_PARAM = "-runtime-shared-library-path=/Applications/Adobe\\ Flex\\ Builder\\ 3/sdks/3.2.0/frameworks/libs/framework.swc,framework_3.2.0.3958.swz,,framework_3.2.0.3958.swf"
  COMPONENTS_PARAM = "-runtime-shared-library-path=vendor/flex/components/bin/components.swc,components.swf"
  DEFAULT_FLAGS = "--warnings=true --strict=true --debug=false" 
  def self.compile_swf(project)
    puts "compiling #{project}"
    project_path = "vendor/flex/#{project}/src/#{project}"
    compile_cmd = "#{COMPILER} #{DEFAULT_FLAGS} #{FRAMEWORK_PARAM} #{COMPONENTS_PARAM} -file-specs #{project_path}.mxml"
    #puts compile_cmd

   `mv #{project_path}.swf public/flash/#{project}.swf`
  def self.optimize_swc(library="components")
    `unzip vendor/flex/#{library}/bin/#{library}.swc -d vendor/flex/#{library}/bin/unzip`
    `optimizer -keep-as3-metadata="Bindable,Managed,ChangeEvent,NonCommittingChangeEvent,Transient" -input=vendor/flex/#{library}/bin/unzip/library.swf -output=public/flash/#{library}.swf`
    `rm -rf vendor/flex/#{library}/bin/unzip`

One thing to beware of: make sure your various libraries (.swcs) externally link the framework rsl’s, otherwise they will be a couple 100k bigger with the duplication. By default in flex, libraries merge the framework in, which is counter-productive if you’ve taken steps to dynamically link it in your app.

Getting circle/diamond/etc datapoints on an ActionScript dynamically created Flex charting lineseries 1

Posted by Tim Connor Fri, 11 Apr 2008 18:40:00 GMT

myLineseries.setStyle("itemRenderer", new ClassFactory(DiamondItemRenderer));

It works similarly for lineSegmentRenderers, even custom ones, like Quietly Scheming’s Dashed Line Renderer. I just need to figure out how to set a parameter for the renderer created by the class factory now, so I can use different patterns of spaces to make different dashed and dotted lines.