Fork me on GitHub

Archive for the ‘Tips’ Category

Deep linking with SWFAddress 2.5

The BirdBase Demo Site has been updated to use the latest – development version – of SWFAddress.

If you see errors like this:

[Fault] exception, information=ArgumentError: Error #1063: Argument count mismatch on com.asual.swfaddress::SWFAddress$/_setValue(). Expected 2, got 1.
at Function/http://adobe.com/AS3/2006/builtin::apply()
at flash.external::ExternalInterface$/_callIn()
at Function/()

Then update your SWFAddress Actionscript and Javascript from either the Demo Site on Github or the Asual repository here.

The BirdBase Demo Site has been updated to use the latest BirdBase lib, 0.8.2, and we will push the changes into the BirdBase repo shortly.

Tips: Updating Strings Dynamically

Loading the strings initially

A commenter just asked, ‘Docs say “The TextService supports runtime dynamic reloading of strings, so if these are reloaded, in say, a different language, all your IHaveUpdateableText instances will be reformatted and updated immediately.”
How do I reload strings dynamically?’

Good question. Let’s start by seeing how the strings are loaded in the first place.

The strings are kept – initially – in the configuration.yml file. It’s convenient and straightforward, and the section looks something like this:

strings:
    home_title:     "Home Section"
    media_title:    "Media Section"
    news_title:     "News Section"

The configuration is loaded into the ConfigurationService by the D_Services command in org.birdbase.framework.controller.core.

Once the configuration is loaded successfully, we parse the YML into a dictionary and deliver it to various objects:

(ConfigurationService)

97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
private function handleComplete( e:Event ) : void
{
	try
	{
		var d:Dictionary = YAML.decode( e.target.data ) as Dictionary;
 
		setConfiguration( d )
		setStrings( d );
		setPreferences( d );
		setNavigation( d );
 
		eventDispatcher.dispatchEvent( new StateEvent( StateEvent.ACTION, BootManagement.CONFIGURING_SERVICES_COMPLETE ) );
	}
	catch( e:Error )
	{
		fatal( e.message );
		eventDispatcher.dispatchEvent( new StateEvent( StateEvent.ACTION, BootManagement.CONFIGURING_SERVICES_FAILED ) );
	}
}

Line 104 above calls the setStrings function which basically sends the strings chunk of the parsed YML to the TextService:

78
textService.strings = d.strings;

The TextService then updates any updateable components that are registered. And that’s it.

So, the way to update the strings dynamically is to simply set them on the TextService instance. But how do we load a new file in?

Loading a new YML file of strings

The new YML should look exactly like the strings section in the configuration.yml, although the values will be different:

strings:
    home_title:     "Accueil"
    media_title:    "Medias"
    news_title:     "Nouvelles"

So we ought to have an URLLoader to load this for us.

[Inject]
public var textService:ITextService;
 
var loader:URLLoader = new URLLoader();
loader.addEventListener( Event.COMPLETE, handleComplete );
loader.load( new URLRequest( "<path/to/my/new/strings/file.yml>" ) );
 
function handleComplete( e:Event ):void
{
	var d:Dictionary = YAML.decode( e.target.data ) as Dictionary;
	textService.strings = d.strings;
}

And the TextService will update all your registered components.