Archive for category flex
Flex 4 ModuleManager & CSS Inheriting Styles
A client I’m working with has a Flex 3.5 app that’s being migrated to 4.5 and one of the immediate issues we ran into (after we got it compiling successfully) was that the modules didn’t inherit the styles from the main app…worked fine in 3.5, but not in 4.5, so what gives?
So I created a simple PoC with a ModuleLoader and it did indeed pick up on the main apps styles as expected. Next I changed my PoC to resemble the client’s architecture a bit more and used a ModuleManager to load the module — low and behold, the module didn’t inherit the main app’s styles.
After some reading on Adobe’s docs I found the following as the key fix:
Using the ModuleManager class to load modules
You can use the ModuleManager class to load the module. This technique is less abstract than using the tag, but it does provide you with greater control over how and when the module is loaded.
To use the ModuleManager to load a module in ActionScript:
- Get a reference to the module’s IModuleInfo interface by using the ModuleManager getModule() method.
- Call the interface’s load() method.
The application that loads the module should pass in its moduleFactory property. This lets the module know who its parent style manager is. When using the load() method, you can specify the application’s moduleFactory with the fourth parameter, as the following example shows:
info.load(null, null, null, moduleFactory);- Use the factory property of the interface to call the create() method and cast the return value as the module’s class. If you are adding the module to a container, you can cast the return value as an IVisualElement (for Spark containers) or a DisplayObject (for MX containers) so that they can be added to the display list.
So the key is passing in a reference to the moduleFactory when calling the ModuleManager.load() method. The 4th parameter is the moduleManager. If you don’t have a reference the main app lying around, just use:
info.load(null, null, null, FlexGlobals.topLevelApplication.moduleFactory);
Great Ant Build Series for Flex
Many people have asked if we use Maven or Ant for Flex builds…while we like Maven for Java, we don’t like Maven for Flex. It’s not that we don’t like Maven in general (obviously since we’re cool with it for Java), we just found it’s almost too much trouble with Flex. It never fails to make us want to pull our hair out and say “Why bother?” — Yes, we have used FlexMojos and we’re still not convinced. So we use Ant for Flex builds.
Instead of writing our own Ant build tutorial series for Flex, we’d like to push you to Jon Campos’s tutorials:
January 7th, 2010 - Using ANT to build an Application
January 14th, 2010 - Building a Library with ANT
January 19th, 2010 - Building the HTML Wrapper with ANT
January 20th, 2010 - Building a Custom HTML Wrapper with ANT
January 21st, 2010 - Including Assets Files with ANT
January 26th, 2010 - Building a Library and Application with ANT
January 28th, 2010 - Building ASDocs with ANT
February 2nd, 2010 - Run Flex Unit Tests from ANT
February 4th, 2010 - Run FlexMonkey Tests from ANT
February 9th, 2010 - The Master Flex ANT File
Thanks for an awesome series Jon.
As a side note, if someone can convince me that mvn + flex is better/easier than ant by all means ping me. brianr@webappsolution.com
Some Helpful Settings For Maven Builds
Posted by admin in actionscript, air, eclipse, flash builder, flex, flex builder, maven on December 20th, 2010
When running Maven builds, there are typically a few settings that are useful to have in your ~/.bash_profile (for Mac or similar, depending on your shell) to help get things off on the right foot.
Set memory usage to 1024M minimum.
export MAVEN_OPTS=-Xmx1024m
Set the path to the appropriate SDK for Flash Builder
FLASH4_SDK=’/Applications/Adobe Flash Builder 4 Plug-in/sdks/3.5.0′
Set the path for ADL if building AIR applications
ADL_PATH=${FLASH4_SDK}/bin
Set the path to the Flash Player for launching FlexUnit tests
FLASH_PLAYER_PATH=’/Applications/Adobe Flash Builder 4 Plug-in/Player/mac/Flash Player.app/Contents/MacOS’
Append these to the current path
export PATH=${PATH}:${ADL_PATH}
export PATH=${PATH}:${FLASH_PLAYER_PATH}
Substitution Tokens in Resource Bundle Strings in Flex
Posted by brianr in flex, resource bundle on December 9th, 2010
There’s many times where you want to use a Resource Bundle String in-conjunction with variable data. People often breakup the RB String into 2 pieces like so:
part1=My name is
part2=and I like
And then put it back together in AS like:
var part1:String = ResourceManager.getInstance().getString('Labels', 'part1');
var name:String = "Brian Riley";
var part2:String = ResourceManager.getInstance().getString('Labels', 'part2');
var likes:String = "beer.";
var myStr:String = part1 + " " + name + " " + part2 + " " + likes;
Which works, but it’s a lot of unnecessary code. Take advantage of the tokens allowed in RBs and do the following:
likes=My name is {0} and I like {1}
var likes:String = ResourceManager.getInstance().getString('Labels', 'likes', ["Brian Riley", "beer."]);
The ResourceManager class will automatically substitue the tokens {0} and {1} in order and replace them with the array of strings provided as the last param in the getString() method.
Much simpler, right?
This seems to make embedded fonts play nice in both MX and Spark components in almost every situation. The one I couldn’t seem to get around was mx:Legend.