当前位置: 动力学知识库 > 问答 > 编程问答 >

Need help xml CDATA in flash as2

问题描述:

i need help with CDATA when i use it it show in browser window and all attributes that inside CDATA

For example my xml file looks like this

<?xml version='1.0' encoding='utf-8'?>

<project>

<projecttext>

<contenttext><![CDATA[<h1>text</h1>]]></contenttext>

</projecttext>

</project>

and i get in browser window this

<h1>text</h1>

my flash script is

//

//IMPORTS AND STAGE INIT

//

stop();

import flash.display.*;

import flash.events.*;

import flash.filters.*;

import caurina.transitions.Tweener;

import caurina.transitions.properties.ColorShortcuts;

ColorShortcuts.init();

//

Stage.scaleMode = "noScale";

Stage.align = "TL";

//

//XML DOCUMENT INIT

//

var XMLdaten = new XML();

XMLdaten.ignoreWhite = true;

XMLdaten.load(_global.modulexml);

//XMLdaten.load("xml/contentpage.xml");

//

//MEDIA LOADER

//

mediaLoader = function (item, link, mcap) {

var my_mcl:MovieClipLoader = new MovieClipLoader();

var mclListener:Object = new Object();

my_mcl.addListener(mclListener);

//this happens when loading is completed

mclListener.onLoadComplete = function(mc:MovieClip):Void {

Tweener.removeTweens(item);

Tweener.removeTweens(mcap);

Tweener.addTween(item,{_x:0, time:1, transition:"easeOutExpo"});

Tweener.addTween(mcap,{_x:0, time:1, transition:"easeOutExpo", delay:0.1});

mc_project.scrollpane.container.smask._height = mc_project.scrollpane.container._height;

};

my_mcl.loadClip(link,item);

};

//

//ADD PROJECT DETAIL MODE

//

addDetail = function () {

//

attachMovie("mc_project","mc_project",getNextHighestDepth(),{_x:Math.floor(Stage.width/2)-470, _y:Stage.height, _alpha:100});

scbgr = new flash.geom.Rectangle();

scbgr.left = 5;

scbgr.right = 10;

scbgr.top = 5;

scbgr.bottom = 70;

pheight = Math.floor(Stage.height-_root.XMLoptions_headerheight-_root.XMLoptions_footerheight);

mc_project.scrollpane.scbg.scale9Grid = scbgr;

mc_project.scrollpane.scbg._height = pheight-95-Math.floor(slideshowheight);

mc_project.scrollpane.smask._height = pheight-95-Math.floor(slideshowheight);

//

//ASSIGNING TEXT

//

//MOVING TEXT IF CONTENT EMPTY

//

mc_project.scrollpane.container.content_txt.autoSize = "left";

mc_project.scrollpane.container.content_txt.styleSheet = cssfile;

mc_project.scrollpane.container.content_txt.htmlText = XMLdaten_projecttext;

//

//ASSIGNING MEDIA

//

myoffset = 0;

mc_project.scrollpane.container.content_txt._width = 890;

mc_project.scrollpane.container.smask._height = pheight-95;

//

//MAKE PROJECT DETAIL VISIBLE

//

mc_project.scrollpane.container.setMask(mc_project.scrollpane.smask);

Tweener.removeTweens(mc_project);

lockText = function () {

mc_project.scrollpane.container.content_txt.autoSize = "none";

};

if (ss_activated) {

Tweener.addTween(mc_project,{_y:slideshowheight+5, time:0.5, transition:"easeOutExpo"});

} else {

Tweener.addTween(mc_project,{_y:5, time:0.5, transition:"easeOutExpo"});

}

setTimeout(lockText,100);

//

//PROJECT TEXT SCROLLING

//

sa = 30;

//

if (mc_project.scrollpane.container._height<=mc_project.scrollpane.smask._height) {

mc_project.scrollpane.scbg._visible = false;

mc_project.scrollpane.scrollbar._visible = false;

} else {

mc_project.scrollpane.scbg._visible = true;

mc_project.scrollpane.scrollbar._visible = true;

}

//

mc_project.scrollpane.scrollbar.onRollOver = function() {

this.useHandCursor = true;

Tweener.addTween(this.hover,{_alpha:100, time:0.5, transition:"easeOutSine"});

};

mc_project.scrollpane.scrollbar.onRollOut = function() {

Tweener.addTween(this.hover,{_alpha:0, time:0.5, transition:"easeInSine"});

};

mc_project.scrollpane.scrollbar.onReleaseOutside = function() {

Tweener.addTween(this.hover,{_alpha:0, time:0.5, transition:"easeInSine"});

};

//on scrollbar press

mc_project.scrollpane.scrollbar.onMouseDown = function() {

if (this.hitTest(_root._xmouse, _root._ymouse) && mc_project.scrollpane.container._height>mc_project.scrollpane.smask._height) {

this.startDrag(false,mc_project.scrollpane.scbg._x,mc_project.scrollpane.scbg._y,mc_project.scrollpane.scbg._x,mc_project.scrollpane.scbg._height-this._height);

mc_project.scrollpane.container.onEnterFrame = scrollThumbs;

dragging = true;

}

};

//on scrollbar release

mc_project.scrollpane.scrollbar.onMouseUp = function() {

stopDrag();

dragging = false;

delete this.onEnterFrame;

};

//scrolling functionality

scrollThumbs = function () {

var positionvar = -this._parent.scrollbar._y*(((this._height-this._parent.scrollbar._height+5)/(this._parent.scbg._height-this._parent.scrollbar._height))-1);

this.Y = (positionvar-this._y)*.2;

this._y += this.Y;

this._y = parseInt(this._y);

if (Math.abs(positionvar-this._y)<1 && !dragging) {

delete this.onEnterFrame;

}

};

//

//MOUSE SCROLL FUNCTION

//

function mousescrolling() {

mouseListener = new Object();

//

mouseListener.onMouseWheel = function(delta) {

if (mc_project.scrollpane.container._height>mc_project.scrollpane.smask._height) {

if (delta>0) {

stopDrag();

mc_project.scrollpane.container.onEnterFrame = scrollThumbs;

if (mc_project.scrollpane.scrollbar._y>mc_project.scrollpane.scbg._y && (mc_project.scrollpane.scrollbar._y-mc_project.scrollpane.scbg._y)<sa) {

mc_project.scrollpane.scrollbar._y -= Math.floor(mc_project.scrollpane.scrollbar._y-mc_project.scrollpane.scbg._y);

} else if (mc_project.scrollpane.scrollbar._y>mc_project.scrollpane.scbg._y && (mc_project.scrollpane.scrollbar._y-mc_project.scrollpane.scbg._y)>=sa) {

mc_project.scrollpane.scrollbar._y -= sa;

}

} else {

stopDrag();

mc_project.scrollpane.container.onEnterFrame = scrollThumbs;

if (mc_project.scrollpane.scrollbar._y<(mc_project.scrollpane.scbg._height-mc_project.scrollpane.scrollbar._height) && (mc_project.scrollpane.scbg._height-mc_project.scrollpane.scrollbar._y-mc_project.scrollpane.scrollbar._height)<sa) {

mc_project.scrollpane.scrollbar._y += Math.floor(mc_project.scrollpane.scbg._height-mc_project.scrollpane.scrollbar._y-mc_project.scrollpane.scrollbar._height);

} else if (mc_project.scrollpane.scrollbar._y<(mc_project.scrollpane.scbg._height-mc_project.scrollpane.scrollbar._height) && (mc_project.scrollpane.scbg._height-mc_project.scrollpane.scrollbar._y-mc_project.scrollpane.scrollbar._height)>=sa) {

mc_project.scrollpane.scrollbar._y += sa;

}

}

}

};

Mouse.addListener(mouseListener);

return mouseListener;

}

mouseListener = mousescrolling();

};

//

//RESIZE POSITIONING

//

position = function () {

pheight = Math.floor(Stage.height-_root.XMLoptions_headerheight-_root.XMLoptions_footerheight);

//

mc_project._x = Math.floor(Stage.width/2)-470;

if (ss_activated) {

slideshow._x = Math.floor(Stage.width/2)-460;

}

mc_project._alpha = 100;

mc_project.scrollpane.scbg._height = pheight-90-Math.floor(slideshowheight);

mc_project.scrollpane.smask._height = pheight-90-Math.floor(slideshowheight);

mc_project.scrollpane.scrollbar._y = 0;

//

if (mc_project.scrollpane.container._height<=mc_project.scrollpane.smask._height) {

mc_project.scrollpane.scbg._visible = false;

mc_project.scrollpane.scrollbar._visible = false;

} else {

mc_project.scrollpane.scbg._visible = true;

mc_project.scrollpane.scrollbar._visible = true;

}

};

//

resizeListener = new Object();

resizeListener.onResize = function() {

position();

};

Stage.addListener(resizeListener);

//

//XML DOCUMENT LOAD & DATA ASSIGN

//

XMLdaten.onLoad = function(success) {

if (success) {

//

XMLdaten_medialink = [];

XMLdaten_mediaheight = [];

XMLdaten_mediacaption = [];

//

maxv = _root.maxv;

if (maxv != undefined) {

pheight = Stage.height-maxv;

} else {

pheight = Stage.height;

}

regularImageLoad = function (link, item) {

my_mcl = new MovieClipLoader();

mclListener = new Object();

my_mcl.loadClip(link,item);

};

//

XMLdaten_projecttext = XMLdaten.firstChild.childNodes[0];

if (XMLdaten.firstChild.childNodes[1].attributes["height"] != undefined && XMLdaten.firstChild.childNodes[1].attributes["height"] != "") {

ss_activated = true;

slideshowtype = XMLdaten.firstChild.childNodes[1].attributes["slideshowtype"];

slideshowheight = parseInt(XMLdaten.firstChild.childNodes[1].attributes["height"]);

_global.slideshowxml = XMLdaten.firstChild.childNodes[1].attributes["slideshowxml"];

createEmptyMovieClip("slideshow",getNextHighestDepth(),{_x:0, _y:0});

slideshow._x = Math.floor(Stage.width/2)-460;

slideshow._y = 3;

regularImageLoad(slideshowtype,slideshow);

}else{

slideshowheight = 0;

}

//

//Load Stylesheet

cssfile = new TextField.StyleSheet();

cssfile.load("xml/styles.css");

cssfile.onLoad = function(success) {

if (success) {

cssloaded = true;

if(XMLdaten_projecttext!=""){

addDetail();

}

} else {

cssloaded = false;

}

};

//

xmlloaded = true;

} else {

xmlloaded = false;

}

};

i use xml business portfolio template

thanks to all

网友答案:

I found this blog post on the same topic.

Apparently, one of two things is happening:

  1. You are in fact not accessing CDATA correctly (This is what heartcode is referring to):

    Now, the way that you should be accessing CDATA in Flash is perhaps a little different to what you’d expect. CDATA should have no effect on how you access your XML – it’s a parsing instruction, right?. Well Flash treats it as part of the XML structure, so if you want to access the data inside the CDATA element, you have to treat the CDATA as a node in itself. Its actually quite easy though. Instead of accessing the contents of CDATA with childNode.nodeValue or childNodes, you should be using childNode.firstChild.nodeValue.

    In your case, it should be XMLdaten.firstChild.firstChild.firstChild.nodeValue, as childNodes[0] yields the same node as firstChild.

  2. The Flash player isn't parsing the CDATA correctly

    If you run a few traces on HTML formatting that you try to send via CDATA, you’ll notice that all of the < and > characters are transformed into their encoded versions, < and >. This poses a minor problem because if you just try to whack HTML from your XML into a dynamic textbox, the formatting won’t work properly and you’ll get the characters < and > appearing, along with the HTML formatting commands – because the < and > characters are encoded.

    Unless in your text you have any < or > characters you need displayed as such, you could run XMLdaten_projecttext = XMLdaten_projecttext.split(’&lt;’).join(’<’).split(’&gt;’).join(’>’)

网友答案:

Try this: XMLdaten_projecttext = XMLdaten.firstChild.childNodes[0].nodeValue;

Good luck, Rob

分享给朋友:
您可能感兴趣的文章:
随机阅读: