Wednesday, February 28, 2007

Styling with CSS and XML - Actionscript translations

One thing which I found in dealing with all of the flash 8 and flex projects is that in translations for styling of CSS and XML - I've found a pretty effective way to do this so that in projects you can have a stylesheet applied with variable font sizes and XML being parsed at the same time.

It starts out with the fact that you have a TextLoader class which loads in the text similar to:


public static function loadText( aStyleSheetPath:String, anInterfaceDir:String ):Void
{
Logger.log("INFO", TextLoader.toString() + " loading stylesheets and text.");
var styleSheetDir:String = aStyleSheetPath;
var interfaceDir:String = anInterfaceDir;
var currentLanguage:String = LanguageManager.getLanguage();
var cssFilePath:String = styleSheetDir + "stylesheet_" + currentLanguage + ".css" ;
var xmlFilePath:String = interfaceDir + "interface_" +currentLanguage+".xml";

/*---------------------------------------------------------------------
* Now we load in the stylesheet and once it is loaded we can then
* get the current interface and load this.
*---------------------------------------------------------------------*/

var stylesheet:TextField.StyleSheet = new TextField.StyleSheet();
stylesheet.load( cssFilePath );
stylesheet.onLoad = Delegate.create(TextLoader, function( status ) {
/*---------------------------------------------------------------------
* Once the stylesheet is loaded we then apply this to the text and
* then get it applied and the text loaded.
*---------------------------------------------------------------------*/

var interfaceTextXml:XML = new XML();
interfaceTextXml.ignoreWhite = true;
interfaceTextXml.load( xmlFilePath );
interfaceTextXml.onLoad = Delegate.create(TextLoader, function( isLoaded:Boolean ) {
if( isLoaded ) {
Logger.log("INFO", TextLoader.toString() + "Interface XML loaded ["+ xmlFilePath+"] " );
Logger.log("INFO", TextLoader.toString() + "StyleSheet CSS loaded ["+cssFilePath+"] " );
TextLoader.initialize(interfaceTextXml, stylesheet);
TextLoader.notifyListeners( new TextLoadedEvent() );
} else {
Logger.log("ERROR", TextLoader.toString() + "Unable to load xml ["+xmlFilePath+"] " );
}
});
});

}



This then loads in a stylesheet and an xml file. Then once the class loads I dispatch a notifyListeners event which then lets all other classes know that the stylesheet and xml are loaded.

I then make any listeners implement the right events.

The TextLoader class then has a method called renderText which then looks like the following:



public static function renderText( t:TextField, textFromXML:String, aTextId:String ):Void {
var cssEntry:String = "";
var defaultFont:String = "ID_DefaultFont";
t.styleSheet = styleSheet;

if( aTextId.indexOf("_he") == -1 )
{
t.embedFonts = true;
} else {
t.embedFonts = false;
}

t.html = true;
t.multiline= true;
/****************************************************************************
* Do a check if this particular class exists, if it doesn't then don't apply
* the class.
*************************************************************************/
cssEntry = ( styleSheet.getStyle( "."+ aTextId ) != undefined ) ? "class='"+aTextId+"'" : "" ;

/****************************************************************************
* Check if the active language is hebrew and forward this to the hebrew
* parsing engine to reverse the text.
*************************************************************************/
if( LanguageManager.getLanguage() == "he" )
{
t.embedFonts = false;
if( styleSheet.getStyle( "."+defaultFont ) && (styleSheet.getStyle( "."+ aTextId ) == undefined) ) {
t.htmlText = Hebrew.getConversion( textFromXML, t, defaultFont );
} else {
t.htmlText = Hebrew.getConversion( textFromXML, t, aTextId );
}
//Logger.log("DEBUG", "TextLoader().renderText - Hebrew ["+t.htmlText+"] ");
return;
}

// If there is a default font, set it to this but not if there is already
// a style defined.
if( styleSheet.getStyle( "."+defaultFont ) && (styleSheet.getStyle( "."+ aTextId ) == undefined) ) {
cssEntry = "class='"+defaultFont+"'";
}

t.htmlText = "

" + textFromXML + "

";
//Logger.log("INFO", "TextLoader().renderText - cssStyle ["+t.htmlText+"] ["+aTextId+"] ");
}

public static function getText( aTextId:String ):String {
return interfaceXML['idMap'][ aTextId ].firstChild.nodeValue.toString();
}




This allows for the renderText to then be used like TextLoader.renderText() which can then render the text applying the stylesheet similar to

-- this then allows for a stylesheet to have an exact id applied to it.

This is pretty organized. Not bad a for a scientology coder, eh?

Sunday, February 25, 2007

Train derailment in the united kingdom - Volunteer ministers at the scene


A very large train derailment occurred - seems like 48 different people were injured but with some seriously injured.

The train was traveling at 95mph and then violently moved from side to side and then derailed. Pretty crazy. The volunteer ministers are being rounded up to help assist those in care. I posted some shots to take a look.

check out the volunteer ministers here

Thursday, February 22, 2007

International Association of Scientologists Animation Shots (3d)



The International Association of Scientologists put up a new update to their site. I uploaded some of the screen shots from their flash intro which uses some 3d stuff. It's pretty cool.



Tuesday, February 20, 2007

Incredible bump mapping with papervision


This is quite cool - a new papervision bump map which is definitely bad ass and contemporary.

Check it out here

Wednesday, February 14, 2007

Chick corea wins 2 grammy awards


This is really cool. Chick Corea, one of the all time legends of Jazz won 2 grammys for an album he did for L. Ron Hubbard's The Ultimate Adventure which is a sci fi book he did a while back.

Check out chick's site here

Friday, February 9, 2007

New article from blitz agency on skinning


There is a new article from the blitz agency on how to use papervision with 3dsmax to skin properly.

Check out the article here

Monday, February 5, 2007

Psychiatric Drugs and Anger Management Curricula—A Perspective on School Violence


This is not related, to flash, but the citizens commission on human rights published a very informative link and white paper on violence in our schools today. I really think all should take a look.

Take a look at another article

Friday, February 2, 2007

London Scientology Org opens



London Scientology org released a new org a few months back which I forgot to blog about. This org is absolutely beautiful. It was opened by the Chairman of the Board, Religious Technology Center, David Miscavige who gave a very cool speech about the org and the area there. I've seen a lot of photos of the org.

Check it out the london grand opening speech here