Solved

XML text only loads 9 cahracters

Posted on 2007-03-24
7
198 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Creating Instructional Tutorials  

For Any Use & On Any Platform

Contextual Guidance at the moment of need helps your employees/users adopt software o& achieve even the most complex tasks instantly. Boost knowledge retention, software adoption & employee engagement with easy solution.

 

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

PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

Question has a verified solution.

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

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,…
I have been doing hardcore actionscripting for some time; and needless to say I have faced a lot of problems in just understanding others' code rather than understanding what the code executes. A programmer's life can become hell when there are a lo…
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 what frame rate is, how to control it and what effect it has on the video.

734 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