我是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