1 Reply Latest reply on Feb 4, 2011 1:39 PM by pauland

    Embedding Flash strange behaviour

    paashoas

      Hi guys,

       

      I use some flash file:a slideshow with a thumbsmenu.

      Each thumb has an eventlistener that are set on the Load Event.

      When I test it seperatly from Flex it works fine but when I put it flex via the Designer View it works differently.

      The events on the thumbs only work if the main image has not been displayed yet...


      1. // GreenSock actionscript
        import gs.*;
        import gs.easing.*;
      2. //////////////////////////////////////////////////////////////////
        //                   Load XML
        //////////////////////////////////////////////////////////////////
      3. var thumbsLoader:MovieClipLoader = new MovieClipLoader();
        var thumbsListener:Object = new Object();
        var padding_x:Number = 17;
        var padding_y:Number = 17;
        var counter:Number = 1;
        var multiplier:Number = 0;
        var thumbClicks:Number = 0;
      4. var currentImageViaThumbclick = new Array();
        currentImageViaThumbclick[0] = 0;
      5. var currentImage:Number = 0;
        var imageLoader:MovieClipLoader = new MovieClipLoader();
        var loadListener:Object = new Object();
      6. var prevImg;
        var slideOnBreak = 0;
        //var xmlPath = "http://localhost/pixieflocknl/public/portfolio/browse/artwork/";
        var xmlPath = "config.xml";
        var photos_xml = new XML();
        photos_xml.ignoreWhite = true;
        var imageList:Array = new Array();
        photos_xml.onLoad = function(success) {
            if (success) { // ----------- load successful
                // ----------- convert XML content to an array
                imageList = photos_xml.firstChild.childNodes;
                // ----------- Do some action once xml is loaded
                loadThumbs();
               
                // ----------- Do some action once xml is loaded
            } else {
                // ----------- problem loading, check path
                trace("Error loading photos_xml");
            }
        };
        //////////////////////////////////////////////////////////////////
        //                   Load Images
        //////////////////////////////////////////////////////////////////
      7. imageLoader.addListener(loadListener);
      8. loadListener.onLoadInit = function(target_mc:MovieClip, httpStatus:Number):Void {
            TweenLite.to(shell_mc.background_mc, 0.25, {_width:target_mc._width + 20, _height:target_mc._height + 30, ease:Quad.easeOut});
            TweenLite.to(shell_mc.border_mc, 0.25, {_width:target_mc._width, _height:target_mc._height, ease:Quad.easeOut});
            TweenLite.to(shell_mc.mask_mc, 0.25, {_width:target_mc._width, _height:target_mc._height, ease:Quad.easeOut});
           
            // center content
            var clipXTarg = Math.round((Stage.width/2)-((target_mc._width+20)/2)+((thumbContainer._width+20)/2));
            var clipYTarg = Math.round((Stage.height/2)-((target_mc._height+20)/2)+80);
            TweenLite.to(shell_mc, 0.25, {_x:clipXTarg, _y:clipYTarg, ease:Quad.easeOut});
      9.     // find previous image
            if(currentImage == 0){
                var prevImgNum = imageList.length -1;
            }else{
                var prevImgNum = currentImage - 1;
            }
           
            prevImg = shell_mc.pics_mc["pic"+prevImgNum];
            TweenLite.to(prevImg, 0.25, {autoAlpha:0, onComplete:removePrevious});
        }
      10. loadListener.onLoadComplete = function(target_mc:MovieClip):Void {
            TweenLite.to(target_mc, 0.25, {autoAlpha:100, delay:0.25});
            if(slideOnBreak == 0){
                setTimer();
            }else{
                clearInterval(timer);
            }
        }
      11. //////////////////////////////////////////////////////////////////
        //                   Functions List
        //////////////////////////////////////////////////////////////////
      12. function setTimer(){
            timer = setInterval(loadImage, 5000);
        }
      13. function removePrevious(){
            if(prevImg != undefined){
                removeMovieClip(prevImg);
            }
           
            if(thumbClicks > 0){
                currentImage = currentImageViaThumbclick[(currentImageViaThumbclick.length) - 1] + 1;
            }else{
                // increment the current image
                if(currentImage < imageList.length -1){
                    currentImage = currentImage + 1;
                }else{
                    currentImage = 0;
                }
            }
           
        }

      14. function loadImage(){
            var loadURL = imageList[currentImage].attributes.imgurl;
            var targetClip = shell_mc.pics_mc.createEmptyMovieClip("pic"+currentImage,shell_mc.pics_mc.getNextHighestD epth());
            targetClip._alpha = 0;
            clearInterval(timer);
           
            // load the new image
            imageLoader.loadClip(loadURL,targetClip);
        }

      15. function doBreak(){
            //clearInterval(timer);
            stop();
        }
      16. //////////////////////////////////////////////////////////////////
        //                       Thumbs
        /////////////////////////////////////////////////////////////////
      17. thumbsLoader.addListener(thumbsListener);
        thumbsListener.onLoadComplete = function(target_mc:MovieClip):Void {
            TweenLite.to(target_mc, 0.25, {autoAlpha:100, delay:0.25});
            //nieuw
            target_mc.onRelease = function(){
                slideOnBreak = 1;
                       
                var currentThumb = this._name.split('thumb');
                // Pas bij de tweede maal geklikt in thumbsmenu onderstaande code uitvoeren
               
                currentImageViaThumbclick[thumbClicks] = Number(currentThumb[1]);
                   
                thumbClicks = thumbClicks + 1;
               
                var thumbURL = imageList[currentThumb[1]].attributes.imgurl;
                var thumbClip = shell_mc.pics_mc.createEmptyMovieClip("pic"+currentThumb[1],shell_mc.pics_mc.getNextHighe stDepth());
                //thumbClip._alpha = 0;
                //clearInterval(timer);
               
                // load the new image
                imageLoader.loadClip(thumbURL,thumbClip);
               
               
            }
        }
      18. function loadThumbs(){
            for(var i = 0; i < imageList.length-1; i++){
                var loadThumb = imageList[i].attributes.thumb;
                var thumbClip = thumbContainer.thumbs.createEmptyMovieClip("thumb"+i,thumbContainer.thumbs.getNextHighest Depth());
                thumbClip._alpha = 50;//begint vanaf 50 naar 100
               
                thumbClip._x = (multiplier * 50) + (padding_x * multiplier) + padding_x;
                thumbClip._y = padding_y;
                       
                counter++;
                multiplier++;
               
                if(counter%4 == 0){
                    multiplier = 0;
                    counter = 1;
                    padding_y += 60;
                }
               
                // load the new thumb
                thumbsLoader.loadClip(loadThumb,thumbClip);
               
            }
            loadImage();
        }
      19. //////////////////////////////////////////////////////////////////
        //                   On First Load
        //////////////////////////////////////////////////////////////////
        photos_xml.load(xmlPath);
        stop();
        btnpauze.onRelease=function(){
            clearInterval(timer);
            slideOnBreak = 1;
        }
        btnplay.onRelease=function(){
            thumbClicks = 0;
            slideOnBreak = 0;
            setTimer();
        }