Assigning linkage to assets in the library

You can assign linkage identifiers for assets in the library, such as movie clips and font symbols. In Flash, you can set linkage identifiers to sound and image assets in the library. This supports using image and sound files with shared libraries and with the new BitmapData class.

The following example adds a bitmap image in the library with a linkage set to myImage. Then you add the image to the Stage and make it draggable.

To use linkage with bitmap files:

  1. Create a new FLA file called linkBitmap.fla.
  2. Import a bitmap image to the library.
  3. Right-click (Windows) or Control-click (Macintosh) the image in the library, and select Linkage from the context menu.
  4. Select Export for ActionScript and Export in first Frame and type myImage in the Identifier text box.
  5. Click OK to set the linkage identifier.
  6. Select Frame 1 on the Timeline, and type the following code in the Actions panel:
    import flash.display.BitmapData; 
    // Create imageBmp and attach the bitmap from the library.
    var imageBmp:BitmapData = BitmapData.loadBitmap("myImage"); 
    // create movie clip and attach imageBmp
    this.createEmptyMovieClip("imageClip", 10); 
    imageClip.attachBitmap(imageBmp, 2);
    // make the clip draggable
    imageClip.onPress = function() { 
         this.startDrag(); 
    }; 
    imageClip.onRelease = function() { 
         this.stopDrag(); 
    }
    
  7. Select Control > Test Movie to test the document.

    The bitmap in the library appears on the Stage, and the image is draggable.


Flash CS3