Solved

XML text only loads 9 cahracters

Posted on 2007-03-24
7
199 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
MS Dynamics Made Instantly Simpler

Make Your Microsoft Dynamics Investment Count  & Drastically Decrease Training Time by Providing Intuitive Step-By-Step WalkThru Tutorials.

 

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

[Webinar] How Hackers Steal Your Credentials

Do You Know How Hackers Steal Your Credentials? Join us and Skyport Systems to learn how hackers steal your credentials and why Active Directory must be secure to stop them. Thursday, July 13, 2017 10:00 A.M. PDT

Question has a verified solution.

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

This is intended to introduce all collision detection principles in flash, their strengths, weaknesses and workarounds. The main method for Collision Detection in flash is using hitTestObject. But unless you'll be pushing rectangular shapes without …
There are times in your Flash CS4 application when you want more than a simple pointer or a hand, and it's hard to find an ideal walk-through to tell you what to do.  I spent a few days recently learning my way around making custom cursors in Flash,…
The goal of the tutorial is to teach the user how to live broadcast using Flash Media Live Encoder and connecting it to YouTube to broadcast. Log into your Youtube account, choose live stream settings, start live stream from Flash Media Live Enc…
The goal of the tutorial is to teach the user how to use the auto adjust feature and what the different options do. When your video is not working right you can choose the auto adjust feature to help choose your settings.

696 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