SwfMill и тег <bitmap>

В списке рассылки появилась информация о недокументированном пока теге SwfMill - bitmap и в частности о применении его для внедрения растровых изображений в swf как для Flash9, так и для haXe.
Человек, которого зовут Krzysztof Różalski (не возьмусь транслировать это на русский) нашёл её в рассылке по SWFMill.

Ниже приводится рабочий пример, который он использовал с swfmill 0.2.12:

<?xml version="1.0" encoding="iso-8859-1" ?>
<movie version="9">
   <frame>
       <library>
           <bitmap id="banner" import="file.jpg"/>
       </library>
   </frame>
</movie>

class Test{
  static function main() {
      trace("Test.main - 8");
      flash.Lib.current.attachBitmap( flash.display.BitmapData.loadBitmap( "banner" ), 0 );
  }
}

// swfmill simple

<?xml version="1.0" encoding="iso-8859-1" ?>
<movie version="9">
   <library>
           <bitmap id="MyBitmapData" name="MyBitmapData"  import="file.jpg"/>
   </library>
   <frame>
   </frame>
</movie>

//Test.hx
 
import flash.display.BitmapData;
 
class MyBitmapData extends BitmapData
{
   public function new()
   {
       super(0,0);
   }
}
 
class Test
{
   static function main():Void
   {
       var bitmapData:BitmapData;
       #if flash9
           bitmapData = new MyBitmapData();
           flash.Lib.current.addChild( new flash.display.Bitmap( bitmapData, flash.display.PixelSnapping.AUTO, true ) );
       #else flash8
           bitmapData = BitmapData.loadBitmap( "MyBitmapData" );
           flash.Lib.current.attachBitmap( bitmapData, 0 );
       #end
       trace("BitmapData : "+bitmapData.width+" / "+bitmapData.height );
   }
}
 
//Source end

It is important that both "name" and "id" attributes of swfmill bitmap tag are the same - otherwise it won't work in flash9. If "id" is not defined then no bitmap is compiled into swfmill output. On the other hand if "id" is different than "name" there is exception :
ReferenceError: Error #1065: Variable MyBitmapData_linkage is not defined.
MyBitmapData overwrites constructor to simplify creation - no arguments needed because width and height is already defined by imported file.jpg width and height ( in my case the last trace is "Test.hx:25 : BitmapData : 88 / 31" which is correct )

Hope someone will find this useful

P.S. To make it work with Adobe Flash CS3 generated swfs just change MyBitmapData to extern class ( remove class body ) and add width and height on instance creation ( e.g. bitmapData = new MyBitmapData(0,0); ). This is probably forced by fact that MyBitmapData class compiled by CS3 is not overwritten by haXe compiled one - anybody knows is it possible to force that?

Комментарии

-

Криштоф Розальски?

Настройки просмотра комментариев

Выберите нужный метод показа комментариев и нажмите "Сохранить установки".

Отправить комментарий

Содержание этого поля является приватным и не предназначено к показу.
  • Allowed HTML tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <blockcode> <dd>
  • Строки и параграфы переносятся автоматически.
  • Адреса страниц и электронной почты автоматически преобразуются в ссылки.
  • You can enable syntax highlighting of source code with the following tags: <code>, <blockcode>.

Подробнее о форматировании

CAPTCHA
Этот вопрос помогает предотвратить автоматический спам
Image CAPTCHA
Enter the characters shown in the image without spaces, also respect upper and lower case.
To prevent automated spam submissions leave this field empty.