我有一个“score1.as”类,它将从swf访问数据并将其显示出来
我的“finalscore.fla”...我能够成功地将数据传递到我的“finalscore.fla”..但我的问题是:虽然我能够通过跟踪来访问数据,但我不能将它显示给我的动态文本......我想只需输入“txtScore.text = ("Score: " + lol1.go() );
”即可解决问题,但事实并非如此......请帮助......这就是我的代码......我的方式,我正在使用actionscript 3.0 ..
score1.as:
package
{
import flash.display.Loader;
import flash.display.Sprite;
import flash.events.Event;
import flash.net.URLRequest;
public class score1 extends Sprite
{
private var loader:Loader;
public function Parent()
{
loader = new Loader();
loader.contentLoaderInfo.addEventListener(Event.COMPLETE, onLoaded);
loader.load(new URLRequest("savescore.swf"));//This is the swf where in the data came from
}
public function onLoaded(e:Event):void
{
trace(loader.content['currentScore']);
}
public function go():int{
return loader.content['currentScore'];//This is the data being accessed
}
}
}
finalscore.fla:
var lol1:score1 = new score1();
txtScore.text = ("Score: " + lol1.go() ); // This is where I can't display the data
lol1.Parent();//I successfully traced the data
答案 0 :(得分:0)
检查嵌入字体。您可能只嵌入编译时出现的字体中的字符。例如,如果你有一个带有“Hello World!”的文本字段,并且你想要textfield.text = "Jiggly Jello Lord!"
显示为“l ello ord”,因为在编译期间只有那些字符存在于文本字段中。
我仔细研究了你的代码。您需要先致电Parent()
,然后才能获取内容。事实上,将它重命名为构造函数,你应该很好。
package {
import flash.display.Loader;
import flash.display.Sprite;
import flash.events.Event;
import flash.net.URLRequest;
public class score1 extends Sprite {
public var loader:Loader;
public function score1() {
// You need to run this code as your constructor.
loader = new Loader();
loader.contentLoaderInfo.addEventListener(Event.COMPLETE, onLoaded);
loader.load(new URLRequest("savescore.swf"));
}
public function onLoaded(e:Event):void {
trace(loader.content['currentScore']);
}
public function go():int {
return loader.content['currentScore'];
}
}
}
您还希望在访问数据之前等待加载您的内容。为此,在尝试onLoaded
txtScore.text = ("Score: " + lol1.go() );
开火
onLoaded
就知道它是否运行。它会在Event.COMPLETE
触发时被调用。通过相同的扩展,只需从您的类外部注册该事件,或者触发事件,或者在加载数据后完成的任何其他解决方案。
<强> finalscore.fla:强>
var lol1:score1 = new score1();
lol1.loader.contentLoaderInfo.addEventListener(Event.COMPLETE, scoreReady);
function scoreReady(e:Event):void {
txtScore.text = "Score:" + lol1.go();
}