Embedded XML - not working :(

  • nikfiend
  • Novice
  • Novice
  • nikfiend
  • Posts: 20

Post 3+ Months Ago

I have a thumbnail carousel that uses an external XML file, the site we are posting it to doesn't allow for external XML so I switched it to embedded XML. The code verifies but nothing is loaded, can you please take a look and see if there are any errors or give me direction on how to accomplish pulling the XML from a hidden text field as explained in the link below:

http://www.actionscript.org/forums/s....php3?t=122446


Code: [ Select ]
import flash.filters.BlurFilter;
import mx.utils.Delegate;
class oxylus.carousel.Carousel extends MovieClip {
    private var node:XMLNode;
    private var _vertical:Boolean;
    private var _autoMove:Boolean;
    private var _speed:Number;
    private var _maxSpeed:Number;
    private var _radiusx:Number;
    private var _radiusy:Number;
    private var _stopOnRollover:Boolean;
    private var _allButtons:Boolean;
    private var _blurScale:Number;
    private var _hitW:Number;
    private var _hitH:Number;
    private var xml:XML;
    private var Thumbs:Array;
    private var refAngle:Number = 0;
    private var angle:Number;
    private var baseDepth:Number;
    private var once:Boolean = false;
    public function Carousel() {
        Thumbs = new Array();
        xml = new XML();
        xml.ignoreWhite = true;
        xml.onLoad = Delegate.create(this, dataLoaded);
        xml.parseXML("<?xml version=\"1.0\"?>"+
                "<carousel vertical=\"no\" autoMove=\"no\" maxSpeed=\"1\" radiusX=\"145\" radiusY=\"20\" blurScale=\"8\" reflections=\"yes\" showBorder=\"yes\" showTooltip=\"yes\" stopOnRollover=\"yes\" allButtons=\"no\" hitAreaWidth=\"376\" hitAreaHeight=\"300\">"+
    "<image src=\"img/tony.jpg\" tooltip=\"Tony's Story\" link=\"http://www.youtube.com/watch?v=_cgrBatl4gU&feature=PlayList&p=AB9F86531A994FA9&index=16\" target=\"_self\" />"+
    "<image src=\"img/gwendolyn.jpg\" tooltip=\"Gwendolyn's Story\" link=\"http://www.youtube.com/watch?v=qm1kPpcw-RI&feature=PlayList&p=AB9F86531A994FA9&index=13\" target=\"_self\" />"+
    "<image src=\"img/angela.jpg\" tooltip=\"Angela's Story\" link=\"http://www.youtube.com/watch?v=0OwpVViTQm4&feature=PlayList&p=AB9F86531A994FA9&index=7\" target=\"_self\" />"+
    "<image src=\"img/elizabeth.jpg\" tooltip=\"Elizabeth's Story\" link=\"http://www.youtube.com/watch?v=s6pnxjFpmkU&feature=PlayList&p=AB9F86531A994FA9&index=1\" target=\"_self\" />"+
    "<image src=\"img/juanne.jpg\" tooltip=\"Juanne's Story\" link=\"http://www.youtube.com/watch?v=d79ouOG2A1U&feature=PlayList&p=AB9F86531A994FA9&index=0\" target=\"_self\" />"+
    "<image src=\"img/melissa.jpg\" tooltip=\"Melissa's Story\" link=\"http://www.youtube.com/watch?v=tCUtCTxdqtQ&feature=PlayList&p=AB9F86531A994FA9&index=29\" target=\"_self\" />"+
    "<image src=\"img/michael.jpg\" tooltip=\"Michael's Story\" link=\"http://www.youtube.com/watch?v=uoiVBJJkhbU&feature=PlayList&p=AB9F86531A994FA9&index=11\" target=\"_self\" />"+
    "<image src=\"img/jiro.jpg\" tooltip=\"Jiro's Story\" link=\"http://www.youtube.com/watch?v=USd1ggftg4U&feature=PlayList&p=AB9F86531A994FA9&index=4\" target=\"_self\" />"+
    "<image src=\"img/adam1.jpg\" tooltip=\"Adam's Story\" link=\"http://www.youtube.com/watch?v=NaURm0uxOZE&feature=PlayList&p=AB9F86531A994FA9&index=8\" target=\"_self\" />"+
    "<image src=\"img/linda.jpg\" tooltip=\"Linda's Story\" link=\"http://www.youtube.com/watch?v=YmKndZjg1Vw&feature=PlayList&p=AB9F86531A994FA9&index=3\" target=\"_self\" />"+
"</carousel>");
    }
    private function dataLoaded(s) {
        if (!s) {
            trace("Could not load xml ! Check xml (must be carousel.xml)");
            return;
        }
        node = xml.firstChild;
        _vertical = node.attributes.vertical == "yes";
        _autoMove = node.attributes.autoMove == "yes";
        _maxSpeed = _speed=Number(node.attributes.maxSpeed);
        _radiusx = Number(node.attributes.radiusX);
        _radiusy = Number(node.attributes.radiusY);
        _blurScale = Number(node.attributes.blurScale);
        _stopOnRollover = node.attributes.stopOnRollover == "yes";
        _allButtons = node.attributes.allButtons == "yes";
        _hitW = Number(node.attributes.hitAreaWidth)/2;
        _hitH = Number(node.attributes.hitAreaHeight)/2;
        _radiusx = Number(node.attributes.radiusX);
        //
        var p:XMLNode = node.firstChild;
        var i:Number = 0;
        baseDepth = this.getNextHighestDepth();
        for (; p != null; p=p.nextSibling, i++) {
            var tn:MovieClip = this.attachMovie("Thumbnail", "tn"+i, baseDepth+i);
            tn.setData(p, node);
            if (_stopOnRollover) {
                tn.onMouseOver = Delegate.create(this, Pause);
                tn.onMouseOut = Delegate.create(this, Resume);
            }
            Thumbs.push(tn);
            //break;
        }
        angle = 360/Thumbs.length;
        if (!_autoMove) {
            spin();
            this.onMouseMove = mouseMoveHandler;
        } else {
            Resume();
        }
    }
    private function Pause() {
        delete this.onEnterFrame;
    }
    private function Resume() {
        this.onEnterFrame = spin;
    }
    private function spin() {
        for (var i = 0; i<Thumbs.length; i++) {
            var tn:MovieClip = Thumbs[i];
            var crtAngle:Number = (refAngle+i*angle)%360;
            if (crtAngle<0) {
                crtAngle += 360;
            }
            if (_vertical) {
                tn._x = Math.sin((crtAngle)/180*Math.PI)*_radiusy;
                tn._y = Math.cos((crtAngle)/180*Math.PI)*_radiusx;
            } else {
                tn._y = Math.sin((crtAngle)/180*Math.PI)*_radiusy;
                tn._x = Math.cos((crtAngle)/180*Math.PI)*_radiusx;
            }
            //
            var tAngle:Number = (crtAngle+90)%360;
            if (tAngle>180) {
                tAngle = 360-tAngle;
            }
            var minScale:Number = 50;
            var minAlpha:Number = 30;
            tn._xscale = tn._yscale=minScale+(100-minScale)*tAngle/180;
            var lim:Number = 90;
            if (tAngle<=lim) {
                tn.filters = blur(_blurScale-_blurScale*tAngle/lim);
                tn._alpha = minAlpha+(100-minAlpha)*tAngle/lim;
            } else {
                tn.filters = blur[0];
                tn._alpha = 100;
            }
            var crtDepth:Number = baseDepth+Math.floor(2*tAngle/angle);
            if (tn.getDepth() != crtDepth) {
                tn.swapDepths(crtDepth);
            }
            if (!_allButtons) {
                tn.enabled = tAngle>=90;
            }
        }
        refAngle += _speed;
    }
    private function blur(blur) {
        blur = Math.round(blur);
        if (blur<1) {
            return [];
        }
        return [new BlurFilter(blur, blur, 2)];
    }
    private function mouseMoveHandler() {
        if (_xmouse<-_hitW || _xmouse>_hitW || _ymouse<-_hitH || _ymouse>_hitH) {
            return;
        }
        if (!once) {
            once = true;
            Resume();
        }
        if (!_vertical) {
            _speed = _maxSpeed*_xmouse/_hitW;
        } else {
            _speed = _maxSpeed*_ymouse/_hitH;
        }
    }
}
  1. import flash.filters.BlurFilter;
  2. import mx.utils.Delegate;
  3. class oxylus.carousel.Carousel extends MovieClip {
  4.     private var node:XMLNode;
  5.     private var _vertical:Boolean;
  6.     private var _autoMove:Boolean;
  7.     private var _speed:Number;
  8.     private var _maxSpeed:Number;
  9.     private var _radiusx:Number;
  10.     private var _radiusy:Number;
  11.     private var _stopOnRollover:Boolean;
  12.     private var _allButtons:Boolean;
  13.     private var _blurScale:Number;
  14.     private var _hitW:Number;
  15.     private var _hitH:Number;
  16.     private var xml:XML;
  17.     private var Thumbs:Array;
  18.     private var refAngle:Number = 0;
  19.     private var angle:Number;
  20.     private var baseDepth:Number;
  21.     private var once:Boolean = false;
  22.     public function Carousel() {
  23.         Thumbs = new Array();
  24.         xml = new XML();
  25.         xml.ignoreWhite = true;
  26.         xml.onLoad = Delegate.create(this, dataLoaded);
  27.         xml.parseXML("<?xml version=\"1.0\"?>"+
  28.                 "<carousel vertical=\"no\" autoMove=\"no\" maxSpeed=\"1\" radiusX=\"145\" radiusY=\"20\" blurScale=\"8\" reflections=\"yes\" showBorder=\"yes\" showTooltip=\"yes\" stopOnRollover=\"yes\" allButtons=\"no\" hitAreaWidth=\"376\" hitAreaHeight=\"300\">"+
  29.     "<image src=\"img/tony.jpg\" tooltip=\"Tony's Story\" link=\"http://www.youtube.com/watch?v=_cgrBatl4gU&feature=PlayList&p=AB9F86531A994FA9&index=16\" target=\"_self\" />"+
  30.     "<image src=\"img/gwendolyn.jpg\" tooltip=\"Gwendolyn's Story\" link=\"http://www.youtube.com/watch?v=qm1kPpcw-RI&feature=PlayList&p=AB9F86531A994FA9&index=13\" target=\"_self\" />"+
  31.     "<image src=\"img/angela.jpg\" tooltip=\"Angela's Story\" link=\"http://www.youtube.com/watch?v=0OwpVViTQm4&feature=PlayList&p=AB9F86531A994FA9&index=7\" target=\"_self\" />"+
  32.     "<image src=\"img/elizabeth.jpg\" tooltip=\"Elizabeth's Story\" link=\"http://www.youtube.com/watch?v=s6pnxjFpmkU&feature=PlayList&p=AB9F86531A994FA9&index=1\" target=\"_self\" />"+
  33.     "<image src=\"img/juanne.jpg\" tooltip=\"Juanne's Story\" link=\"http://www.youtube.com/watch?v=d79ouOG2A1U&feature=PlayList&p=AB9F86531A994FA9&index=0\" target=\"_self\" />"+
  34.     "<image src=\"img/melissa.jpg\" tooltip=\"Melissa's Story\" link=\"http://www.youtube.com/watch?v=tCUtCTxdqtQ&feature=PlayList&p=AB9F86531A994FA9&index=29\" target=\"_self\" />"+
  35.     "<image src=\"img/michael.jpg\" tooltip=\"Michael's Story\" link=\"http://www.youtube.com/watch?v=uoiVBJJkhbU&feature=PlayList&p=AB9F86531A994FA9&index=11\" target=\"_self\" />"+
  36.     "<image src=\"img/jiro.jpg\" tooltip=\"Jiro's Story\" link=\"http://www.youtube.com/watch?v=USd1ggftg4U&feature=PlayList&p=AB9F86531A994FA9&index=4\" target=\"_self\" />"+
  37.     "<image src=\"img/adam1.jpg\" tooltip=\"Adam's Story\" link=\"http://www.youtube.com/watch?v=NaURm0uxOZE&feature=PlayList&p=AB9F86531A994FA9&index=8\" target=\"_self\" />"+
  38.     "<image src=\"img/linda.jpg\" tooltip=\"Linda's Story\" link=\"http://www.youtube.com/watch?v=YmKndZjg1Vw&feature=PlayList&p=AB9F86531A994FA9&index=3\" target=\"_self\" />"+
  39. "</carousel>");
  40.     }
  41.     private function dataLoaded(s) {
  42.         if (!s) {
  43.             trace("Could not load xml ! Check xml (must be carousel.xml)");
  44.             return;
  45.         }
  46.         node = xml.firstChild;
  47.         _vertical = node.attributes.vertical == "yes";
  48.         _autoMove = node.attributes.autoMove == "yes";
  49.         _maxSpeed = _speed=Number(node.attributes.maxSpeed);
  50.         _radiusx = Number(node.attributes.radiusX);
  51.         _radiusy = Number(node.attributes.radiusY);
  52.         _blurScale = Number(node.attributes.blurScale);
  53.         _stopOnRollover = node.attributes.stopOnRollover == "yes";
  54.         _allButtons = node.attributes.allButtons == "yes";
  55.         _hitW = Number(node.attributes.hitAreaWidth)/2;
  56.         _hitH = Number(node.attributes.hitAreaHeight)/2;
  57.         _radiusx = Number(node.attributes.radiusX);
  58.         //
  59.         var p:XMLNode = node.firstChild;
  60.         var i:Number = 0;
  61.         baseDepth = this.getNextHighestDepth();
  62.         for (; p != null; p=p.nextSibling, i++) {
  63.             var tn:MovieClip = this.attachMovie("Thumbnail", "tn"+i, baseDepth+i);
  64.             tn.setData(p, node);
  65.             if (_stopOnRollover) {
  66.                 tn.onMouseOver = Delegate.create(this, Pause);
  67.                 tn.onMouseOut = Delegate.create(this, Resume);
  68.             }
  69.             Thumbs.push(tn);
  70.             //break;
  71.         }
  72.         angle = 360/Thumbs.length;
  73.         if (!_autoMove) {
  74.             spin();
  75.             this.onMouseMove = mouseMoveHandler;
  76.         } else {
  77.             Resume();
  78.         }
  79.     }
  80.     private function Pause() {
  81.         delete this.onEnterFrame;
  82.     }
  83.     private function Resume() {
  84.         this.onEnterFrame = spin;
  85.     }
  86.     private function spin() {
  87.         for (var i = 0; i<Thumbs.length; i++) {
  88.             var tn:MovieClip = Thumbs[i];
  89.             var crtAngle:Number = (refAngle+i*angle)%360;
  90.             if (crtAngle<0) {
  91.                 crtAngle += 360;
  92.             }
  93.             if (_vertical) {
  94.                 tn._x = Math.sin((crtAngle)/180*Math.PI)*_radiusy;
  95.                 tn._y = Math.cos((crtAngle)/180*Math.PI)*_radiusx;
  96.             } else {
  97.                 tn._y = Math.sin((crtAngle)/180*Math.PI)*_radiusy;
  98.                 tn._x = Math.cos((crtAngle)/180*Math.PI)*_radiusx;
  99.             }
  100.             //
  101.             var tAngle:Number = (crtAngle+90)%360;
  102.             if (tAngle>180) {
  103.                 tAngle = 360-tAngle;
  104.             }
  105.             var minScale:Number = 50;
  106.             var minAlpha:Number = 30;
  107.             tn._xscale = tn._yscale=minScale+(100-minScale)*tAngle/180;
  108.             var lim:Number = 90;
  109.             if (tAngle<=lim) {
  110.                 tn.filters = blur(_blurScale-_blurScale*tAngle/lim);
  111.                 tn._alpha = minAlpha+(100-minAlpha)*tAngle/lim;
  112.             } else {
  113.                 tn.filters = blur[0];
  114.                 tn._alpha = 100;
  115.             }
  116.             var crtDepth:Number = baseDepth+Math.floor(2*tAngle/angle);
  117.             if (tn.getDepth() != crtDepth) {
  118.                 tn.swapDepths(crtDepth);
  119.             }
  120.             if (!_allButtons) {
  121.                 tn.enabled = tAngle>=90;
  122.             }
  123.         }
  124.         refAngle += _speed;
  125.     }
  126.     private function blur(blur) {
  127.         blur = Math.round(blur);
  128.         if (blur<1) {
  129.             return [];
  130.         }
  131.         return [new BlurFilter(blur, blur, 2)];
  132.     }
  133.     private function mouseMoveHandler() {
  134.         if (_xmouse<-_hitW || _xmouse>_hitW || _ymouse<-_hitH || _ymouse>_hitH) {
  135.             return;
  136.         }
  137.         if (!once) {
  138.             once = true;
  139.             Resume();
  140.         }
  141.         if (!_vertical) {
  142.             _speed = _maxSpeed*_xmouse/_hitW;
  143.         } else {
  144.             _speed = _maxSpeed*_ymouse/_hitH;
  145.         }
  146.     }
  147. }
  • Anonymous
  • Bot
  • No Avatar
  • Posts: ?
  • Loc: Ozzuland
  • Status: Online

Post 3+ Months Ago

  • graphixboy
  • Control + Z
  • Mastermind
  • User avatar
  • Posts: 1828
  • Loc: In the Great White North

Post 3+ Months Ago

well part of the problem is that there's nothing to load.

Code: [ Select ]
xml.onLoad = Delegate.create(this, dataLoaded);
Implies that your getting a file from outside of the swf. Without that external file you will never get the onload to fire and will therefore never get those commands to run.

To the best of my knowledge there's no such thing as embedded xml in flash (xml comes from an external file to be parsed). I would convert all your xml content into arrays and grab from there. Here's a tutorial that doesn't use xml for the data.

Post Information

  • Total Posts in this topic: 2 posts
  • Users browsing this forum: No registered users and 10 guests
  • You cannot post new topics in this forum
  • You cannot reply to topics in this forum
  • You cannot edit your posts in this forum
  • You cannot delete your posts in this forum
  • You cannot post attachments in this forum
 
 

© 1998-2014. Ozzu® is a registered trademark of Unmelted, LLC.