Php ming:如何在Flash / Flex中从ming创建的swf加载和访问资产?

时间:2009-10-27 15:02:29

标签: php actionscript-3 flash

我正在使用Ming创建一个库swf,使用下面的第一个代码示例。如何从Flex应用程序访问嵌入式png?这是php / ming代码:

<?php
// Ming to create Library.swf
//-----------------------------------
// Create background...
Ming_setScale(20.0000000);
$movie = new SWFMovie();
ming_useswfversion(7);
$movie->setDimension(550,400);
$movie->setBackground(200, 200, 200);

// Load png file...
$img_file = "src/assets/page0.png";
$png = new SWFBitmap(fopen($img_file, "rb"));

// Add png to movie...
$movie->add($png);

// Export png
$movie->addExport($png, 'png');
$movie->writeExports();

// Save movie to swf
$swfname = dirname(__FILE__);
$swfname .= "/bin-debug/Library.swf";
$movie->save($swfname, 9);

?>

这是我的弹性论文:

// Loading Library.swf (works), trying to access png asset (doesn't work)    
private var loader:Loader = new Loader();
private function onCreationComplete():void {
 loader.contentLoaderInfo.addEventListener(Event.COMPLETE, onComplete);
 loader.load(new URLRequest('Library.swf'));
}
private function onComplete(e:Event):void {
 var resourceClass:Class = loader.contentLoaderInfo.applicationDomain.getDefinition("png") as Class;
}

我不确定png是否正确导出。使用SwfUtils代码(swfutils.riaforge.org)测试Library.swf根本不显示任何导出的类。或者其他可能是错的?

2 个答案:

答案 0 :(得分:0)

我有同样的问题 我使用 ming创建了一个库,并尝试从flex 访问它,但不起作用。

我之前只使用过这个,因为我需要某个url使用Loader类来检索Class对象,我可以使用它来为Canvas设置 backgroundImage

但是我认为ming my导出的 swf比flex编译的swf版本更低,但遗憾的是它无法识别嵌入的类名。

答案 1 :(得分:0)

您需要在代码中使用assignSymbol函数。

#!/usr/bin/ruby
require 'ming/ming'
include Ming
use_SWF_version(9)
set_scale(20.00000000)
@m = SWFMovie.new
@m.set_dimension(640, 480)
@bm = SWFBitmap.new("./common/MatrixFilter.jpg")
@m.add(@bm)

@text = SWFText.new
@font = SWFFont.new("./common/test.ttf")

@text.set_font(@font)
@text.set_color(0, 0, 0, 0xff)
@text.set_height(20)
@text.move_to(100, 100)
@text.add_string( "The quick brown fox jumps over the lazy dog. 1234567890")
@i1 = @m.add(@text)
@i1.set_depth(1)
@m.next_frame

@m.assign_symbol(@text, "mytext")
@m.assign_symbol(@bm,"mybitmap")
@m.save("assignSymbol.swf")

然后在Flex中使用类似的东西:( FlashDevelop项目)

package 
{
    import flash.display.MovieClip;
    import flash.display.Sprite;
    import flash.display.Bitmap;
    import flash.events.Event;

    /**
     * ...
     * @author DefaultUser (Tools -> Custom Arguments...)
     */

    public class Main extends Sprite 
    {
        [Embed(source="my_clip.swf", symbol="circle")]
        private static var Circle:Class;

        [Embed(source="App.swf", symbol="star")]
        private static var Star:Class;

        [Embed(source="App.swf", symbol="square")]
        private static var Square:Class;        

        [Embed(source = 'assignSymbol.swf', symbol = 'mytext')]
        private static var Mytext:Class;

        [Embed(source='assignSymbol.swf', symbol='mybitmap')]       
        private static var Mybitmap:Class;      

        public function Main():void 
        {
            if (stage) init();
            else addEventListener(Event.ADDED_TO_STAGE, init);
        }

        private function init(e:Event = null):void 
        {
            var circle:Sprite = new Circle();
            addChild(circle);
            circle.x = 100;
            circle.y = 100;

            var star:Sprite = new Star();
            addChild(star);
            star.x = 200;
            star.y = 100;

            var square:Sprite = new Square();
            addChild(square);
            square.x = 300;
            square.y = 100; 

            var mybitmap:Bitmap = new Mybitmap();
            addChild(mybitmap);
            mybitmap.x = 300;
            mybitmap.y = 300;               

            var mytext:Sprite = new Mytext();
            addChild(mytext);
            mytext.x = 0;
            mytext.y = 200;
            removeEventListener(Event.ADDED_TO_STAGE, init);
            // entry point
        }
    }
}