当前在线人数16152
首页 - 分类讨论区 - 电脑网络 - 闪客一族版 -阅读文章
未名交友
[更多]
[更多]
文章阅读:Please help - how to assign the loaded txt/xml file's arr
[同主题阅读] [版面: 闪客一族] [作者:flyingcow] , 2011年11月20日22:50:05
flyingcow
进入未名形象秀
我的博客
[上篇] [下篇] [同主题上篇] [同主题下篇]

发信人: flyingcow (宝珠黛汝), 信区: Flash
标  题: Please help  - how to assign the loaded txt/xml file's array to variables?
发信站: BBS 未名空间站 (Sun Nov 20 22:50:05 2011, 美东)

我是刚接触actionscript没到一个星期的新手,请版上的高手指教:

I use following flash actionscript code, got from online, to load the "
Loading.txt" file:

var myTextLoader:URLLoader = new URLLoader();
myTextLoader.addEventListener(Event.COMPLETE, onLoaded);
function onLoaded(e:Event):void {
    var myArrayOfLines:Array = e.target.data.split(/\n/,",");
}
myTextLoader.load(new URLRequest("Loading.txt"));

In "Loading.txt", the data of object in a row is (Dim1 Dim2 Dim3 OX OY OZ)
is:
60,12,9,-50,-50,50
84,12,9, 50, 50,50

Then I use onLoaded[i-1][j-1], in a loop to get the data in row i and column
j of the array, but I got some error message. Can somebody help me on this?
I am totally new to actionscript. The loop I used is like
var ArrayRows:int=2 // how to automatically get the number of rows of the
txt file?

for(iObj=0;iObj<ArrayRows;iObj++){
    Dim1 = ObjDimArray[iObj][0]
    Dim2 = ObjDimArray[iObj][1]
    Dim3 = ObjDimArray[iObj][2]
   
    OX = ObjOriginArray[iObj][3]
    OY = ObjOriginArray[iObj][4]
    OZ = ObjOriginArray[iObj][5]
}

Also, seems most people recommend using xml and I compiled an xml file "
Loading.xml" for above "Loading.txt" as below

<?xml version="1.0" encoding="utf-8"?>
<All>
<Equipment Num="1">
<Manufacturer>HW</Manufacturer>
<Length>60</Length>
<Width>12</Width>
<Thickness>9</Thickness>

<OriginX>-50</OriginX>
<OriginY>-50</OriginY>
<OriginZ> 50</OriginZ>
</Equipment>

<Equipment Num="2">
<Manufacturer>HW</Manufacturer>
<Length>84</Length>
<Width>12</Width>
<Thickness>9</Thickness>

<OriginX>50</OriginX>
<OriginY>50</OriginY>
<OriginZ>50</OriginZ>
</Equipment>
</All>

I used following code to load the "Loading.xml". I would like to use a loop
to read all values and assign to a variable. Can anybody teach me how to do
that?

var myXML:XML = new XML();
var XML_URL:String = "Loading.xml";
var myXMLURL:URLRequest = new URLRequest(XML_URL);
var myLoader:URLLoader = new URLLoader(myXMLURL);
myLoader.addEventListener("complete", xmlLoaded);
function xmlLoaded(event:Event):void
{
myXML = XML(myLoader.data);
trace("Data loaded.");
}

Please help  - how to assign the loaded txt/xml file's array to variables?

I use following flash actionscript code, got from online, to load the "
Loading.txt" file:

var myTextLoader:URLLoader = new URLLoader();
myTextLoader.addEventListener(Event.COMPLETE, onLoaded);
function onLoaded(e:Event):void {
    var myArrayOfLines:Array = e.target.data.split(/\n/,",");
}
myTextLoader.load(new URLRequest("Loading.txt"));

In "Loading.txt", the data of object in a row is (Dim1 Dim2 Dim3 OX OY OZ)
is:
60,12,9,-50,-50,50
84,12,9,  50, 50,50

Then I use onLoaded[i-1][j-1], in a loop to get the data in row i and column
j of the array, but I got some error message. Can somebody help me on this?
I am totally new to actionscript. The loop I used is like
var ArrayRows:int=2 // how to automatically get the number of rows of the
txt file?

for(iObj=0;iObj<ArrayRows;iObj++){
    Dim1 = ObjDimArray[iObj][0]
    Dim2 = ObjDimArray[iObj][1]
    Dim3 = ObjDimArray[iObj][2]
   
    OX = ObjOriginArray[iObj][3]
    OY = ObjOriginArray[iObj][4]
    OZ = ObjOriginArray[iObj][5]
}

Also, seems most people recommend using xml and I compiled an xml file "
Loading.xml" for above "Loading.txt" as below

<?xml version="1.0" encoding="utf-8"?>
<All>
<Equipment Num="1">
<Manufacturer>HW</Manufacturer>
<Length>60</Length>
<Width>12</Width>
<Thickness>9</Thickness>

<OriginX>-50</OriginX>
<OriginY>-50</OriginY>
<OriginZ> 50</OriginZ>
</Equipment>

<Equipment Num="2">
<Manufacturer>HW</Manufacturer>
<Length>84</Length>
<Width>12</Width>
<Thickness>9</Thickness>

<OriginX>50</OriginX>
<OriginY>50</OriginY>
<OriginZ>50</OriginZ>
</Equipment>
</All>

I used following code to load the "Loading.xml". I would like to use a loop
to read all values and assign to a variable. Can anybody teach me how to do
that?

var myXML:XML = new XML();
var XML_URL:String = "Loading.xml";
var myXMLURL:URLRequest = new URLRequest(XML_URL);
var myLoader:URLLoader = new URLLoader(myXMLURL);
myLoader.addEventListener("complete", xmlLoaded);
function xmlLoaded(event:Event):void
{
myXML = XML(myLoader.data);
trace("Data loaded.");
}

非常感谢!
--

※ 来源:·WWW 未名空间站 海外: mitbbs.com 中国: mitbbs.cn·[FROM: 64.126.]

[上篇] [下篇] [同主题上篇] [同主题下篇]
[转寄] [转贴] [回信给作者] [修改文章] [删除文章] [同主题阅读] [从此处展开] [返回版面] [快速返回] [收藏] [举报]
 
回复文章
标题:
内 容:


未名交友
将您的链接放在这儿

友情链接


 

Site Map - Contact Us - Terms and Conditions - Privacy Policy

版权所有,未名空间(mitbbs.com),since 1996