加载在AS3中嵌入图像

编程入门 行业动态 更新时间:2024-10-24 14:19:59
本文介绍了加载在AS3中嵌入图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

OK,我觉得哑问这个,但我花了整个下午试图弄明白,都没有成功。

在AS3,我想将图像添加到库(姑且称之为image.png),并只用code实例吧。

我成功的实例化一个外部图像这样

VAR PLOAD:装载机=新的Loader(); pLoad.load(新的URLRequest(image.png)); 的addChild(PLOAD);

但无论怎样我试过了,我不能做同样的加载方式,从库中的形象。这是怎么一回事?

另外:我已经看到了[嵌入]语法,但最好我想避免硬codeD映像的名字,那就是,我要选择一个图像,从而生成图像的名称,编程 解决方案

看起来是这样工作的:

VAR PDEF:类= getDefinitionByName(image.png)为类; 变种_image:的BitmapData =新PDEF(10,10); m_pSprite =新的Sprite(); m_pSprite.graphics.beginBitmapFill(_image); m_pSprite.graphics.drawRect(0,0,_image.width,_image.height); m_pSprite.graphics.endFill(); 的addChild(m_pSprite)

看起来丑陋和unnecesarily复杂,虽然。任何其他办法吗?

OK, I feel dumb asking this, but I've spent the whole afternoon trying to figure it out, without success.

In AS3, I want to add an image to the Library (let's call it image.png) and instantiate it using just code.

I succeeded in instantiating an external image this way

var pLoad:Loader = new Loader(); pLoad.load(new URLRequest("image.png")); addChild(pLoad);

But no matter what I tried, I can't do the same loading the image from the library. How is that done?

Aside : I've seen the [embed] syntax but ideally I'd like to avoid hardcoded image names, that is, I want to choose an image, and thus generate the image name, programatically.

解决方案

Looks like this works :

var pDef:Class = getDefinitionByName("image.png") as Class; var _image:BitmapData = new pDef(10, 10); m_pSprite = new Sprite(); m_pSprite.graphics.beginBitmapFill(_image); m_pSprite.graphics.drawRect(0, 0, _image.width, _image.height); m_pSprite.graphics.endFill(); addChild(m_pSprite)

Looks ugly and unnecesarily complex, though. Any other way?

更多推荐

加载在AS3中嵌入图像

本文发布于:2023-11-23 15:47:25,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1622007.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:图像   加载

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!