Disable code in a section?
A Flash Developer Resource Site

Results 1 to 7 of 7

Thread: Disable code in a section?

  1. #1
    steals free argos catalogues
    Join Date
    Oct 2006
    Location
    Manchester, England
    Posts
    77

    Disable code in a section?

    I'm making a thingy where you input some stuff in a form, and it saves it to a file to open it into a HTML-enabled dynamic text box in flash.
    I don't want people putting custom HTML code in it though. How do I format it so anything in there comes out as pure text (but allow bold colour italic etc!)

  2. #2
    Senior Member catbert303's Avatar
    Join Date
    Aug 2001
    Location
    uk
    Posts
    11,222
    If you're using PHP to write the file you could try using the strip_tags function to clean out unwanted HTML,

    $cleanedString = strip_tags($theTextWithHtmlTags, '<b><i><font>');

    should remove any HTML tags except <b>, <i> and <font>

  3. #3
    steals free argos catalogues
    Join Date
    Oct 2006
    Location
    Manchester, England
    Posts
    77
    no i mean reading into the flash lol from a variable. uses the htmltext thing in flash.

  4. #4
    Flashkit historian Frets's Avatar
    Join Date
    Oct 2000
    Location
    flashkit
    Posts
    8,792
    I'm sorry but this is not making sense.
    If your making it to write a .txt then you must be making it in a server side program.
    hence... catbert303 has already provided a solution to strip the tags.

    If you want tags stripped before they are displayed in the swf .... well
    we do have flash forums for that.

  5. #5
    steals free argos catalogues
    Join Date
    Oct 2006
    Location
    Manchester, England
    Posts
    77
    im not WRITING to a txt. im loading a string from one. the string is in html. the writing ive got working, the user is able to enter html though - i just need to know a html tag or something that i can put round the string to disable certain code.

  6. #6
    Quote Originally Posted by -AJRAD-
    im not WRITING to a txt. im loading a string from one. the string is in html. the writing ive got working, the user is able to enter html though - i just need to know a html tag or something that i can put round the string to disable certain code.
    I think they understand. You started off with:
    Quote Originally Posted by -AJRAD-
    I'm making a thingy where you input some stuff in a form, and it saves it to a file...
    What they are trying to say is to do your filtering when the user submits the form. If you use PHP to handle the form and save to a file, then you have much more powerful, built-in tools to strip out unwanted HTML tags than you would in Flash.

  7. #7
    Senior Member catbert303's Avatar
    Join Date
    Aug 2001
    Location
    uk
    Posts
    11,222
    I don't know, if you are doing this in flash does actionscript support regular expressions yet? (I'm a few versions behind) If so you could perhaps use them to filter the text.

    If not and you know the content in the file would be well formed XHTML you could use the XML object in Flash to help clean up the HTML - here is a very rough example (maybe need some work):

    Code:
    // a test string of HTML to work with
    var src = '<b>Hello <span>world</span></b><i>This is a test <font color="#ff00ff">test!</font></i> <a href="#" class="some-class">a link</a>';
    // the tags and attributes to allow
    var allowedTags = {b: 1, i: 1, font: 1, a: 1};
    var allowedAttrs = {color: 1, href: 1};
    
    // create an XML object
    var x = new XML("<root>" + src + "</root>");
    
    function buildString(node) {
    	var str = "";
    	
    	if (node.nodeType == 3) { // if it's a text node just add it to the string
    		str += node.nodeValue;
    	} else if (allowedTags[node.nodeName.toLowerCase()]) { // the tag is allowed
    		str += "<" + node.nodeName; 
    		for (var a in node.attributes) { // add any allowed attributes
    			if (allowedAttrs[a]) {
    				str += " " + a + '="' + node.attributes[a] + '"';
    			}
    		}
    		str += ">";
    	}
    	
    	if (node.hasChildNodes) {
    		for (var i = 0; i < node.childNodes.length; ++i) {
    			str += buildString(node.childNodes[i]);
    		}
    	}
    	if (allowedTags[node.nodeName.toLowerCase()]) {
    		str += "</" + node.nodeName + ">";
    	}
    	return str;
    }
    
    str = buildString(x.firstChild);
    trace(src);
    trace(str);
    Doing all this on the server side with PHP when the file is saved would definitely be easier

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width


HTML5 Development Center

Poll by Flashkit.com