[英]Php ming: How to load and access assets from a ming-created swf in Flash/Flex?
I'm using Ming to create an library swf, using the first code example below. 我正在使用Ming使用下面的第一个代码示例来创建库swf。 How can I access the embedded png from my Flex application? 如何从Flex应用程序访问嵌入式png? Here's the php/ming code: 这是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);
?>
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. 我不确定png是否正确导出。 Testing the Library.swf with SwfUtils code (swfutils.riaforge.org) doesn't show any exported classes at all. 使用SwfUtils代码(swfutils.riaforge.org)测试Library.swf根本不显示任何导出的类。 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. 好吧,我有一个同样的问题,我用ming创建了一个库, 并尝试从flex访问它,但是不起作用。
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. 我之所以只使用它,是因为我需要某种方式使用Loader类来获取某个URL,以检索Class对象,例如,我可以使用它为Canvas设置backgroundImage 。
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. 但是我认为通过ming my导出的swf的版本比flex编译的swf低,并且不幸的是它无法识别嵌入式类的名称。
You need to use assignSymbol
function within code. 您需要在代码内使用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")
Then use something like this in Flex: (FlashDevelop project) 然后在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
}
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.