Not yet rated

Problem

See how to access custom symbols in SWF library from Adobe Flash Builder.

Solution

Use TinkSpark library which has APIs for easily accessing the symbols from a SWF from within Flex apps.

Detailed explanation

Create a fla file and design a symbol, name it say MySymbol and save the file as library.fla.

Check "Export for ActionScript" and place the base class as flash.display.Sprite / flash.display.MovieClip

Compile and keep the swf in appropriate directory.

Download the TinkSpark source from http://code.google.com/p/tink/source/checkout and add the package to your flex project:

Then write the following code:

import ws.tink.core.Library;
import ws.tink.events.LibraryEvent;
import ws.tink.managers.LibraryManager;

private function loadLibrary():void
{
     var library:Library = LibraryManager.libraryManager.createLibrary( "assetsLibrary" );
     library.addEventListener( LibraryEvent.LOAD_COMPLETE, onAssetsLibraryLoadCompleteHandler, false, 0, true );
     library.loadSWF("library.swf" ); //provide the path of library.swf, pls note library.swf is alos exported as AS3.0
}


private function onAssetsLibraryLoadCompleteHandler( event:LibraryEvent ):void
{
    EventDispatcher( event.currentTarget ).removeEventListener( event.type, arguments.callee );
    var library:Library = LibraryManager.libraryManager.getLibrary( "assetsLibrary" );

    var AssetSymbol:Class = library.getDefinition( "MySymbol" );
   addChild( new AssetSymbol() as Sprite );
}

And you are done :)

Warm Regards
Deepanjan Das
http://deepanjandas.wordpress.com/

 


+
This work is licensed under a Creative Commons Attribution-Noncommercial-Share Alike 3.0 Unported License. Permissions beyond the scope of this license, pertaining to the examples of code included within this work are available at Adobe.

Report abuse

Related recipes