?
Solved

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

Posted on 2005-02-27
7
Medium Priority
?
276 Views
Last Modified: 2012-06-27
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
Comment
Question by:Aspirin99
[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
  • 2
  • 2
7 Comments
 
LVL 11

Expert Comment

by:Buffon
ID: 13416417
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
 
LVL 1

Author Comment

by:Aspirin99
ID: 13416638
That's pretty much the same thing I posted above. So, anyone have an idea of why mine are screwed up?
0
 
LVL 39

Accepted Solution

by:
blue-genie earned 2000 total points
ID: 13417707
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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
LVL 11

Expert Comment

by:Buffon
ID: 13417843
what is the problem with apostrophes :) you just dont want them in textfied?
0
 
LVL 39

Expert Comment

by:blue-genie
ID: 13417847
they break strings in the code

nightmare of note.
0
 
LVL 1

Author Comment

by:Aspirin99
ID: 13421947
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
 
LVL 39

Expert Comment

by:blue-genie
ID: 13426911
i assume u got sorted on incorporating it
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.

Question has a verified solution.

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

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 last time I worked with Flash and Socket connections was in AS1. A recent project required flash connecting to a Socket, and sending receiving information - we figured it would be easy enough - we all know about the socket policy documents and c…
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.
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.
Suggested Courses

764 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