我是flash,actionscript和类/方法/静态/实例范例的新手。我有一个我使用的类,它加载一个PNG文件并将其添加到舞台上,然后我可以用鼠标操作它。我想要做的是在png文件的顶部添加一些文本。当用户点击并拖动png文件时,我希望文本能够坚持下去,基本上可以将它作为png的一部分,覆盖它,合并它们,将它们分组,等等。如何将文字叠加到动画片段对象上?
这是我用来加载png的类。
package {
import flash.display.MovieClip;
import flash.display.Loader;
import flash.events.*;
import flash.net.URLRequest;
public class element_icon extends MovieClip {
public function element_icon(type) {
var imageLoader:Loader = new Loader();
var theURL:String = "images/" + type + ".png";
var imageRequest = new URLRequest(theURL);
imageLoader.contentLoaderInfo.addEventListener(IOErrorEvent.IO_ERROR, onIOError);
imageLoader.contentLoaderInfo.addEventListener(Event.COMPLETE, onComplete);
imageLoader.load(imageRequest);
function onIOError(e:IOErrorEvent):void{
var theURL:String = "images/default.png";
var imageRequest = new URLRequest(theURL);
imageLoader.contentLoaderInfo.addEventListener(Event.COMPLETE, onComplete);
imageLoader.load(imageRequest);
}
function onComplete(evt:Event) {
addChild(imageLoader.content);
}
}
}
}
这让我比以前更加深入。我现在的问题是,我不能再拖拽(以前)的影片剪辑(现在)的精灵。 ReferenceError:错误#1069:在flash.text.TextField上找不到属性stopDrag,并且没有默认值。 \t at alchemy_v_0_fla :: MainTimeline/dropIt() 当我尝试点击精灵时,我得到一个文本选择光标,有没有办法“光栅化”它,所以它不像文本行为? – Miebster 2011-03-13 23:58:48
你需要'text.selectable = false;'和'text.mouseEnabled = false',可能'sprite.mouseChildren = false' – 2011-03-14 00:14:43
@MajorApus是的,你可以栅格化它。我用一个例子更新了答案。 – 2011-03-14 00:18:07