• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 283
  • Last Modified:

How to deal with Apostrophe's from XML import into Flash

I have a dynamic text box that I create with createTextField. It will recieve data from an XML file. If you know the answer to this questions, you know what the apostrophes are doing in my text box. I've tried setting the text box properties to HTML, as you can see below, but it doesn't help.  Is there a solution to this besides editing the XML?

            _root.scrollingTextMc.createTextField("myTitleText", 4, 0, 0, 10, 10);
            _root.scrollingTextMc.myTitleText.type = "dynamic";
            _root.scrollingTextMc.myTitleText.autoSize = true;
            _root.scrollingTextMc.myTitleText.embedFonts = true;
            _root.scrollingTextMc.myTitleText.html = true;
//
      myformat = new TextFormat();
      myformat.color = 0x344139;
      myformat.font = "BankGothic";
      myformat.size = 18;
_root.scrollingTextMc.myTitleText.setTextFormat(myformat);
0
Aspirin99
Asked:
Aspirin99
  • 3
  • 2
  • 2
1 Solution
 
BuffonCommented:
I used this code:

createTextField("txt_txt", 4, 0, 0, 10, 10);
txt_txt.type = "dynamic";
txt_txt.autoSize = true;

var xml:XML = new XML();
xml.ignoreWhite = true;
xml.onLoad = function()
{
     var arr:Array = new Array();
     for (var node:XMLNode = xml.firstChild.firstChild;node != null;node = node.nextSibling)
     {
          arr.push(node.firstChild.firstChild.nodeValue);
     }
    txt_txt.text = arr;
}
xml.load("c:/1.xml");


in my xml there are apostrophes and the textfield looks fine.
0
 
Aspirin99Author Commented:
That's pretty much the same thing I posted above. So, anyone have an idea of why mine are screwed up?
0
 
blue-genieCommented:
a simple way is to use a find and replace sequence to replace the ' with `

if that's acceptible, you can use something like this....

function searchandreplace(the_string, search_string, replace_string, occurrences, backward) {
     if (search_string == replace_string) {
          return the_string;
     }
     var found = 0;
     if (backward == true) {
          var pos = the_string.lastIndexOf(search_string);
          while (pos>=0) {
               found++;
               var start_string = the_string.substr(0, pos);
               var end_string = the_string.substr(pos+search_string.length);
               the_string = start_string+replace_string+end_string;
               pos = the_string.lastIndexOf(search_string, start_string.length);
               if (found == occurrences) {
                    pos = -1;
               }
          }
     } else {
          var pos = the_string.indexOf(search_string);
          while (pos>=0) {
               found++;
               var start_string = the_string.substr(0, pos);
               var end_string = the_string.substr(pos+search_string.length);
               the_string = start_string+replace_string+end_string;
               pos = the_string.indexOf(search_string, pos+replace_string.length);
               if (found == occurrences) {
                    pos = -1;
               }
          }
     }
     return the_string;
}

then to use this method ....

var value = 'Question: ' add questionMC1.text;
value = searchandreplace(value, """, "`");

so, if questionMC1.text has a single or double quote pulled from xml, which will break further code, it now replaces it with `

blu.
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
BuffonCommented:
what is the problem with apostrophes :) you just dont want them in textfied?
0
 
blue-genieCommented:
they break strings in the code

nightmare of note.
0
 
Aspirin99Author Commented:
Thanks. I am not sure of how to work that into my xml loader. Can you give me a pointer on how to incorporate your code into this?

-----------------------------------------------------
onClipEvent(load) {

// XML Object ------------------------------------------      
_root.songList = new XML();
         _root.songList.ignoreWhite = true;
// --------------- XML ON LOAD -------------------------
_root.songList.onLoad = function(success) {
  if (success) {
// --------------- DEFINE SOUND OBJECTS AND POPULATE LIST COMPONENT--------------
_root.numberOfSongs = _root.songList.firstChild.childNodes.length;
_root.indexSongNumber = _root.numberOfSongs-1;
for (a=0; a < _root.numberOfSongs; a++) {
      _root["song" + a] = new Sound();
      _root["xmlSong" + a]=_root.songList.firstChild.childNodes[a].childNodes[1].childNodes;
      _root["xmlSongTitle" + a]=_root.songList.firstChild.childNodes[a].childNodes[0].childNodes;

// Below is where I populate my list component with the song titles, but the list component does not have a problem with the apostrophes. See the comments further down for the dynamic text box.

      //_root.song_list.addItem(_root["xmlSongTitle" + a]);
}
//---------------------------------------------------------
var nodes:Array = this.firstChild.childNodes;

      for(var i:Number = 0; i < nodes.length; i++){
      var children:Array = nodes[i].childNodes;
_root.song_list.addItem(children[0].firstChild.nodeValue, children);
      }
var listener:Object = new Object();
listener.change = function(evt:Object):Void
                  {
    var data:Object = evt.target.selectedItem.data;

//--------------------- BELOW IS THE PROBLEM BOX ---------------------------------------------------------------------------
// The _root.mySongTitle is the dynamic text box I'm having the problem with.

   _root.mySongTitle = data[0].firstChild;

    _root["song" + _root.nextSong].loadSound(data[1].firstChild, true);
                  }
    _root.song_list.addEventListener("change", listener);
// ------------------ IF XML CAN'T LOAD ----------------------
} else {
      trace("not loaded yet");  
  }
}
// LOAD EXTERNAL XML FILE--------------------------

_root.songList.load("audioPlayer.xml");
      
}// END CLIP EVENT LOAD -------------------------------------------------------------



0
 
blue-genieCommented:
i assume u got sorted on incorporating it
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 3
  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now