Solved

XML text only loads 9 cahracters

Posted on 2007-03-24
7
194 Views
Last Modified: 2010-04-03
Hi ,

I'm loading text into flash via an xml file but am having a slight problem - the length of the imported string is only 9 characters long ?? heres the actionscript and the xml file

myXML = new XML();
myXML.ignoreWhite = true;
myXML.load("/xml/banner.xml");
myXML.ref = this;
myXML.onLoad = function(succes){
    if(succes){
        var root = this.firstChild
        nodes = root.childNodes
        for(var i=0; i<nodes.length; i++) {        
            subnodes = nodes[i].childNodes
            text = subnodes[0].firstChild.toString()  
        }
    } else trace("Error loading XML document")
}
i = 1;
max = length(text);
trace(max);


<?xml version="1.0" encode="UTF-8"?>
<data>
<title name="HomepageBanner1">
<comments>blahblahblahblahblahblahblahblahblah</comments>
</title>
</data>

can someone please help.

Dave
0
Comment
Question by:daveboyle99
  • 3
  • 3
7 Comments
 
LVL 13

Expert Comment

by:FLAASHER
ID: 18785247
make sure ur text field is multy line or increase it width
0
 

Author Comment

by:daveboyle99
ID: 18785679
hi flaasher,

I'm pretty sure its the code thats at fault. If i just set

index="some text string";
max = length(text);
trace(max);

then i get the actual length of the string not just "9" returned.......... its wierd
0
 
LVL 13

Expert Comment

by:FLAASHER
ID: 18786284
//max = length(text);


what is text in the prvous line ???
u must say :
max = length(index);// this will give u 16
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

Author Comment

by:daveboyle99
ID: 18791938
i agree, its a typo on my part

would it be possible for you to try my code from my first post and you will see the problem of which i speak. basically the text that is loaded from the xml is measured at a length of  9 despite its actual length. it has nothin to do with how i've displayed that text on screen

Dave
0
 
LVL 13

Expert Comment

by:FLAASHER
ID: 18791955
send me the fla file
0
 

Author Comment

by:daveboyle99
ID: 18795829
flaasher you dont need the xml file the code is in my first post
0
 
LVL 2

Accepted Solution

by:
khoama earned 125 total points
ID: 18809021
Your problem is:

when the statement

i = 1;
max = length(text);
trace(max);

is executed, the variable text is not defined since the XMl has not been 100% loaded, the length of 'undefined' is 9.You can check this by adding a trace statement in the onLoad event handler and one trace statement at the end of the block of code. You'll see the that the one stay at the end of the code will come first. The suggested work around for this is you put your max,length blah blah in a function and call this when the xml is loaded. This is my code, based on yours


myXML = new XML();
myXML.ignoreWhite = true;

myXML.load("/xml/banner.xml");
myXML.ref = this;

myXML.onLoad = function(succes){
    if(succes){
            
            trace("This should come first")
            
        var root = this.firstChild
        nodes = root.childNodes
        for(var i=0; i<nodes.length; i++) {        
            subnodes = nodes[i].childNodes
            text = subnodes[0].firstChild.toString()  
        }
            
            runMe();
            
    } else trace("Error loading XML document")
}

//run this function after the XML has finish loading
function runMe()
{
      max = length(text);
      trace(max);
}


trace("This should come last");
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
How to put actionscript code for a button? 6 117
Action Script commands 4 305
Action Script coding 1 173
Begin mp4 video on first frame 6 167
Recently, I was asked to recommend a tracking system to be implemented on a clients website. As the entire site was built on flash, my first thought was to suggest custom built tracking system. However, our company at that point of time didn't h…
Here are some practices and techniques that can be adopted into your Flash/Flex application development process. Note: Not all "performance tips" provide an immediately-recognizable benefit.   This article does not include timing validation data,…
The goal of the tutorial is to teach the user how to how to record live broadcast.
The goal of the tutorial is to teach the user how to select the video input device. Make sure you have an input device that in connected and work and recognized by Adobe Flash Media Live Encoder and select it in the “video input” menu.

911 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

23 Experts available now in Live!

Get 1:1 Help Now