SunQuest
 
           Flash Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 
Go Back   Dev Articles Community ForumsWeb DesignFlash Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
Stay one step ahead of the competition. Evaluate and give feedback on some of the hottest web development tools on the market today. Make your opinion heard! Click Here
  #1  
Old February 6th, 2003, 07:38 AM
themuppeteer themuppeteer is offline
Junior Member
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Feb 2003
Posts: 8 themuppeteer User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Question reading 2dimensional array from file

Hello,
How do you read in a 2 dimensional array of ints from a file ?
Its for the levels of my game...

Reply With Quote
  #2  
Old February 7th, 2003, 01:10 PM
pakcik_kantin pakcik_kantin is offline
Junior Member
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Sep 2002
Location: Kantin
Posts: 18 pakcik_kantin User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
OK, i tried the easiest way of my beginning in FLASH with loadvariables, coz
i'm a beginner..
To avoid headache thinking of a dimensional array, i would prefer to simplify it by using
long code in flash (more code in flash).It is because, coding in FLASH, is quite easier
. But it's worth for beginner

First oFF, we want to have a simple 2 dimensional array
PHP Code:
 myArray[0][0]="Pakcik"
myArray[0][1]="Kantin"

myArray[1][0]="Makcik"
myArray[1][1]="Sekolah" 


Let start with a load action from text file named Text.txt. The text file would have a code like these:
&myDimensionalArray=pakcik:kantin,makcik:sekolah&quit=quit

Then in the FLASH 5.0

1.loadVariablesNum ("Text.txt", 0);(Loaded after frame 1, just to make sure it is loaded, maybe frame 5)
2.The next frame, we try to make it as a 1 dimensional array first, by splitting the comma (,) first
PHP Code:
 newTwoDArray myDimensionalArray.split(",");
    
newTwoDArrayLength=newTwoDArray.length;
    
    for (var 
i=0i<newTwoDArrayLength i++) 
    {
        
//If you want to view it in a dynamic text simply use this
        //nextText+="This is " add a[i];
        //If you want to view it , use trace
        
trace("Array[" add i add "]=" add newTwoDArray[i]);
    } 

#This is to check wether the Array is built OK
#If it is working then we can continue
#Output

Array[0]=pakcik:kantin
Array[1]=makcik:sekolah


3. In the same frame (If it is OK to view) , we can start splitting our array into 2 dimensional array
PHP Code:
for (var 0i<newTwoDArrayLengthi++) 
    {    
        
tmpArray = new Array();    
        
tmpArray newTwoDArray[i].split(":");
        
tmpArrayLength =     tmpArray.length;
        
newTwoDArray[i]= new Array();
    
        for (var 
0j<tmpArrayLengthj++) 
        {        
            
newTwoDArray[i][j]="Array[" add i add "][" add j add "]=" add tmpArray[j];
            
            
//If you want to view it in a dynamic text simply use this
            //nextText+=newTwoDArray[i][j];
            //If you want to view it , use trace
            
trace (newTwoDArray[i][j]);
        }
    } 

#The purpose of tmpArray is that, we cannot split the newTwoDArray[i] and assigning back to it again

#Output

Array[0]=pakcik:kantin
Array[1]=makcik:sekolah

Array[0][0]=pakcik
Array[0][1]=kantin
Array[1][0]=makcik
Array[1][1]=sekolah

#The first 2 lines is the 1 dimensional array, the rest is the 2 dimesional array



Hope this will help, based on what i understand.
Conclusion of the function
PHP Code:
 newTwoDArray myDimensionalArray.split(",");
    
newTwoDArrayLength=newTwoDArray.length;
for (var 
0i<newTwoDArrayLengthi++) 
    {    
        
tmpArray = new Array();    
        
tmpArray newTwoDArray[i].split(":");
        
tmpArrayLength =     tmpArray.length;
        
newTwoDArray[i]= new Array();
    
        for (var 
0j<tmpArrayLengthj++) 
        {        
            
newTwoDArray[i][j]="Array[" add i add "][" add j add "]=" add tmpArray[j];
            
            
//If you want to view it in a dynamic text simply use this
            //nextText+=newTwoDArray[i][j];
            //If you want to view it , use trace
            
trace (newTwoDArray[i][j]);
        }
    } 



Last edited by pakcik_kantin : February 7th, 2003 at 01:35 PM.

Reply With Quote
  #3  
Old February 8th, 2003, 07:18 AM
themuppeteer themuppeteer is offline
Junior Member
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Feb 2003
Posts: 8 themuppeteer User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Talking coool

thnx a lot for the large explication!
I'l get right on it ;-)

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsWeb DesignFlash Development > reading 2dimensional array from file


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 3 hosted by Hostway