gpt4 book ai didi

android - As3 从时间轴引用一个类

转载 作者:行者123 更新时间:2023-11-29 02:09:07 25 4
gpt4 key购买 nike

我不明白这是怎么回事?我可以将其他类导入时间线并使用它们就好了,但是这个类给我带来了重大问题?我正在从我的服务器上解析 XML 数据,它给我的错误看起来像这样。

时间线引用及使用:

     import networkScores;

var network:networkScores = new networkScores();
addChild(network);

score1Textfield.text = network.score1.toString();

类定义:

 package 
{
import flash.net.URLLoader;
import flash.net.URLRequest;
import flash.events.Event;
import flash.display.MovieClip;

public class networkScores extends MovieClip
{
public var myXML:XML, myXMLNames:XML;
public var xmlLoaderScores = new URLLoader();
public var score1:int;

public function networkScores()
{
xmlLoaderScores.addEventListener(
Event.COMPLETE, xmlLoadedScores);
xmlLoaderScores.load(new URLRequest("pathtoxmlfile"));
}

public function xmlLoadedScores(e:Event):void
{
myXML = new XML(e.target.data);
var qName1:QName = new QName(
"http://www.w3.org/2005/Atom", "score1");
score1 = myXML.descendants(qName1)[0].toString();
}

}

}

我得到的错误:

Scene 1, Layer 'Actions', Frame 4, Line 149 1119: Access of possibly undefined property score1 through a reference with static type networkScores.

1067: Implicit coercion of a value of type networkScores to an unrelated type flash.display:DisplayObject.

这是选角问题吗?

我该如何解决这个问题?

最佳答案

您的时间轴不应试图引用文档类。文档类应该控制一切。有几种方法可以知道何时将对象添加到舞台并准备好处理(例如监听添加到舞台)。一旦您知道该对象已被添加并且您知道您的 xml 已返回,您就可以在您在文档类中公开的子对象上填充一个变量.有关更多信息,请查看此博客文章 http://www.developria.com/2010/04/combining-the-timeline-with-oo.html ,以及此处的随附代码 http://flexdiary.blogspot.com/2010/04/sample-code-for-oop-timeline-insideria.html .

编辑显示代码:

它的代码可能看起来像这样:

package {
public class Main extends MovieClip {
private var _stageInstance:StageInstance;
private var _score:String;
private var _loader:URLLoader;//hold loader in memory so it doesn't gc before it returns
//by using a getter/setter pair, we know when Flash has added the instance to the stage
public function get stageInstance():StageInstance{
return _stageInstance;
}
public function set stageInstance(value:StageInstance):void {
_stageInstance = value;
if (_stageInstance != null && _score != null) {
_stageInstance.score = _score;
}
}
public function onScoreLoaded(e:Event):void {
myXML = new XML(e.target.data);
var qName1:QName = new QName("http://www.w3.org/2005/Atom", "score1");
_score = myXML.descendants(qName1)[0].toString();
if (stageInstance != null) {
stageInstance.score = _score;
}
}
public function Main() {
_loader = new URLLoader();
_loader.addEventListener(Event.COMPLETE, onScoreLoaded);
_loader.load(new URLRequest('pathToXML'));
}
}

}

package {
public Class StageInstance extends MovieClip {
pubic var score1TextField:TextField;//populated by Flash Player
private vare _score:String;
//note how the setter here is doing something useful, not just passing through the value
public function get score():String {
return _score;
}
public function set score(value:String):void {
_score=value;
score1TextField.text=score;
}
public function StageInstance() {
super();
}

}

}

关于android - As3 从时间轴引用一个类,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8455080/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com