Solved

XML text only loads 9 cahracters

Posted on 2007-03-24
7
193 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
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 

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

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

Suggested Solutions

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 …
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 load their YouTube profile onto Flash Media Live Encoder.
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.

707 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

14 Experts available now in Live!

Get 1:1 Help Now