在flash as2中需要帮助xml CDATA

时间:2011-01-12 18:13:35

标签: xml flash cdata

当我使用它时,我需要帮助CDATA显示在浏览器窗口中以及CDATA内的所有属性

例如,我的xml文件看起来像这样

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

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

我进入浏览器窗口

<h1>text</h1>

我的Flash脚本是

//
//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;
    }
};

我使用xml业务组合模板

感谢所有

2 个答案:

答案 0 :(得分:0)

试试这个: XMLdaten_projecttext = XMLdaten.firstChild.childNodes [0] .nodeValue;

祝你好运,Rob

答案 1 :(得分:0)

我在同一主题上找到了这个blog post

显然,发生了两件事之一:

  1. 您实际上没有正确访问CDATA(这是心脏代码所指的):

      

    现在,你应该是这样的   在Flash中访问CDATA可能是一个   与你期望的一点点不同。   CDATA应该对你的方式没有影响   访问你的XML - 这是一个解析   指示,对吗?好闪光   将其视为XML的一部分   结构,所以如果你想访问   你在CDATA元素中的数据   必须将CDATA视为一个节点   本身。它实际上很容易   虽然。而不是访问   CDATA的内容   childNode.nodeValue或childNodes,你   应该使用   childNode.firstChild.nodeValue。

    在你的情况下,它应该是XMLdaten.firstChild.firstChild.firstChild.nodeValue,因为childNodes [0]产生与firstChild相同的节点。

  2. Flash播放器未正确解析CDATA

      

    如果您在HTML上运行一些跟踪   您尝试通过格式发送的格式   CDATA,你会注意到所有&lt;   和&gt;人物被转化为   他们的编码版本,&lt;和&gt;。   这是一个小问题,因为如果   你只是试图打击你的HTML   将XML转换为动态文本框   格式化将无法正常工作   你会得到角色&lt;和&gt;   出现,以及HTML   格式化命令 - 因为&lt;   和&gt;字符被编码。

    除非你的文字中有任何&lt;或者&gt;您需要显示的字符,您可以运行XMLdaten_projecttext = XMLdaten_projecttext.split(’&lt;’).join(’<’).split(’&gt;’).join(’>’)

相关问题