开发者

Php ming: How to load and access assets from a ming-created swf in Flash/Flex?

开发者 https://www.devze.com 2022-12-09 19:09 出处:网络
I\'m using Ming to create 开发者_开发技巧an library swf, using the first code example below. How can I access the embedded png from my Flex application? Here\'s the php/ming code:

I'm using Ming to create 开发者_开发技巧an library swf, using the first code example below. How can I access the embedded png from my Flex application? Here's the php/ming code:

<?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);

?>

And here's my flex essay:

// 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;
}

I'm not sure that the png is exported properly. Testing the Library.swf with SwfUtils code (swfutils.riaforge.org) doesn't show any exported classes at all. Or maybe something else is wrong?


well I have the same problem I create a library with ming and try to access it from flex and doesn't work.

I've only used this because I needed somehow for an certain url using the Loader class to retrieve the Class object that I can use it to set backgroundImage for a Canvas for example.

But I think that swf exported by ming my have a lower version than the flex compiled swf, and it can't recognize the embedded class name unfortunately.


You need to use assignSymbol function within code.

#!/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")

Then use something like this in Flex: (FlashDevelop project)

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
        }
    }
}
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号