android - 如何在 as3, air for android 中加载 xml

标签 android xml actionscript-3 flash air

我正在为 Android 在 Flash 中制作一个应用程序,我想要一些文本出现,所以我认为使用 XML 是一个很好的方法,但我发现这并不像我想象的那么简单。我有一个代码,但那是针对 as2 的,但没有用,所以我的问题是有人有好的工作代码来从 xml 文件中加载一些文本,还是有人知道在 flash 中加载文本的更好方法??? 谢谢回复

最佳答案

下面的代码从您的应用程序目录加载一个 xml 文件(您必须将 xml 文件添加到您的应用程序目录)到 _myXml 属性中。

private var _myXml : XML;
private var _file : File;

public function loadXML() : void {
  _file = File.applicationDirectory.resolvePath("myXml.xml");
  if (_file.exists) {     
    var stream : FileStream = new FileStream();
    stream.open(_file, FileMode.READ);
    var str : String = stream.readUTFBytes(stream.bytesAvailable);
    stream.close();
   _myXml = new XML(str);
  } else {
    trace("WARNING file:" +_file.nativePath + " does not exist");
  } 
}

此代码显示了如何实际使用 XML 文件并从中提取数据

public function loadScenes(lang : String) : Vector.<Scene> {
var scenes : Vector.<Scene> = new Vector.<Scene>();

for each (var scene : XML in _myXml.children()) {
    var sc : Scene = new Scene(loadImage(scene.background.@imageName, scene.background.@width, scene.background.@height), LibraryManager.getFurnitureById(scene.furniture.@furnitureId),scene.furniture.@furnitureId,lang);
    sc.furniture.x = scene.furniture.@x;
    sc.furniture.y = scene.furniture.@y;
    sc.furniture.scaleX = scene.furniture.@scaleX;
    sc.furniture.scaleY = scene.furniture.@scaleY;
    sc.furniture.rotation = scene.furniture.@rotation;
    sc.furniture.gotoAndStop(scene.furniture.@currentFrame);
    sc.setup = true;
    scenes.push(sc);
}
return scenes;

我的 xml 看起来像这样

<scenes>
      <scene>
        <furniture furnitureId="13" currentFrame="1" rotation="0" scaleY="0.4021450653932559" scaleX="0.4021450653932559" y="510.7" x="468.7" id="1"/>
        <background height="640" width="980" imageName="Garden2"/>
      </scene>
      <scene>
        <furniture furnitureId="8" currentFrame="1" rotation="0" scaleY="0.5015106201171875" scaleX="0.5015106201171875" y="516.9" x="488.55" id="2"/>
        <background height="640" width="980" imageName="Garden3"/>
      </scene>
      <scene>
        <furniture furnitureId="15" currentFrame="1" rotation="-0.06605712343630953" scaleY="0.4068730437596716" scaleX="0.4068730437596716" y="454.85" x="518.5" id="1"/>
        <background height="640" width="980" imageName="Garden1"/>
      </scene>
    </scenes>

关于android - 如何在 as3, air for android 中加载 xml,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19862327/

相关文章:

php - 从android中的url获取数据

java - 让 Java 使用制表符而不是空格来缩进

c++ - 如何在ROS环境下用POCO库写XML

actionscript-3 - 使用 Actionscript 3 从 Facebook 加载个人资料图像

apache-flex - trace() 在 Flash Builder 4 中不起作用?

flash - 如何在 ActionScript 中同步多个视频流?

android - ViewBinding vs Kotlin Android Extensions 与合成 View

java - 如果 EditText 为空,则阻止用户关闭警报对话框

java - 通过 Intent 传递图像

c# - 在 Xamarin 中使用 TouchImageView