Solved

XML text only loads 9 cahracters

Posted on 2007-03-24
7
195 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
Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

 

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

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
To view Flash technology content error 4 6,570
Streaming to Flash Media Server with ffmpeg, crashes on start 3 245
Google Chrome Blank White Screens 13 299
flash in chrome 4 99
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 …
Introduction This article is primarily concerned with ActionScript 3 and generally specific to AVM2.  Most suggestions would apply to ActionScript 2 as well, and I've noted those tips that differ between AS2 and AS3. With the advent of ActionS…
In this tutorial viewers will learn how to create a basic shape tween animation in Flash including shape hints for smooth animation Open a new document in Flash: Draw a shape: Select another frame (how long you want the tween to be): Right click and…
The goal of the tutorial is to teach the user how to set there setting in Adobe Flash Media Live Encoder and YouTube for optimal video and audio quality.

806 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