Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 1 of 1
  1. #1
    New to the CF scene
    Join Date
    Jan 2011
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Problem with 2 XML readings

    Hey,
    i'm working on an site and i created a series of flash files who
    Loads thumbs and images from HardcodedXML, and Backgrounds from external XML.

    I added to the external XML an variable for X position and Y position for the HardcodedXML images:
    Code:
    	
    imageHolder.x = xml.slide[pict].@posx;
    imageHolder.y = xml.slide[pict].@posy;
    and everything works, it moves the imageholder around, but as soon I add a height and width variable the first image from the HardcodedXML doesn't load at all untill i switch to a different background.
    so now i have this:
    Code:
    function changePicture(pict:Number):void {
    	pb.visible = true;
    	caption.text = xml.slide[pict].@caption;
    	loader.load(new URLRequest(xml.slide[pict].@data));
    	imageHolder.height = xml.slide[pict].@gova;
    	imageHolder.width = xml.slide[pict].@rohav;
    	imageHolder.x = xml.slide[pict].@posx;
        imageHolder.y = xml.slide[pict].@posy;
        }
    *rohav and gova are Hebrew for height and width
    if i remove height and width so everything is fine...

    all of the code:
    Code:
    import fl.data.DataProvider;
    import fl.data.DataProvider;
    import fl.events.ListEvent;
    import fl.transitions.*;
    import fl.controls.*;
    
    // Pull in image information from XML
    var xml:XML = new XML();
    var xmlLoader:URLLoader = new URLLoader();
    xmlLoader.load(new URLRequest("slideshow_shir.xml"));
    xmlLoader.addEventListener(
    	Event.COMPLETE,
    	function(evt:Event):void {
    			
    		xml = XML(evt.target.data);
    		images.dataProvider = new DataProvider(xml);
    		changePicture(0);
    	}
    );
    
    // Picture changing function
    function changePicture(pict:Number):void {
    	pb.visible = true;
    	caption.text = xml.slide[pict].@caption;
    	loader.load(new URLRequest(xml.slide[pict].@data));
    	imageHolder.height = xml.slide[pict].@gova;
    	imageHolder.width = xml.slide[pict].@rohav;
    	imageHolder.x = xml.slide[pict].@posx;
        imageHolder.y = xml.slide[pict].@posy;
        }
    
    
    // Keep track of current image
    var currentImage:Number = 0;
    
    
    // Wire up progress bar
    pb.source = loader;
    
    // Handle progress bar loading completion
    pb.addEventListener(
    	Event.COMPLETE,
    	function(evt:Event):void {
    		pb.visible = false;
    	}
    )
    
    // Handle combo box changes
    images.addEventListener(
    	Event.CHANGE,
    	function(evt:Event):void {
    		changePicture(images.selectedIndex);
    	}
    );
    
    // Handle button clicks
    next.addEventListener(
    	MouseEvent.CLICK,
    	function(evt:MouseEvent):void {
    		currentImage++;
    		if (currentImage == xml.slide.length()) {
    			currentImage = 0;
    		}
    		images.selectedIndex = currentImage;
    		changePicture(currentImage);
    
    	}
    );
    
    
    // USER CONFIG SETTINGS =====
    var secondsDelay:Number = 2;
    var autoStart:Boolean = true;
    var transitionOn:Boolean = true; // true, false
    var transitionType:String = "Fade"; // Blinds, Fade, Fly, Iris, Photo, PixelDissolve, Rotate, Squeeze, Wipe, Zoom, Random
    var hardcodedXML:String="<photos><image title='001'>001.jpg</image><image title='002'>002.jpg</image><image title='003'>003.jpg</image><image title='004'>004.jpg</image></photos>";
    
    // DECLARE VARIABLES AND OBJECTS 
    var imageList:XML = new XML();
    var currentImageID:Number = 0;
    var imageDP:DataProvider = new DataProvider();
    var slideshowTimer:Timer = new Timer((secondsDelay*10000), 0);
    // END DECLARATIONS
    
    // CODE FOR HARDCODED XML
    imageList = XML(hardcodedXML);
    fl_parseImageXML(imageList);
    // END CODE FOR HARDCODED XML
    
    // EVENTS =====
    imageTiles.addEventListener(ListEvent.ITEM_CLICK, fl_tileClickHandler);
    function fl_tileClickHandler(evt:ListEvent):void
    {
    	imageHolder.imageLoader.source = evt.item.source;
    	currentImageID = evt.item.imgID;
    }
    playPauseToggle_mc.addEventListener(MouseEvent.CLICK, fl_togglePlayPause);
    function fl_togglePlayPause(evt:MouseEvent):void
    {
    	if(playPauseToggle_mc.currentLabel == "play")
    	{
    		fl_startSlideShow();
    		playPauseToggle_mc.gotoAndStop("pause");
    	}
    	else if(playPauseToggle_mc.currentLabel == "pause")
    	{
    		fl_pauseSlideShow();
    		playPauseToggle_mc.gotoAndStop("play");
    	}
    }
    next_btn.addEventListener(MouseEvent.CLICK, fl_nextButtonClick);
    prev_btn.addEventListener(MouseEvent.CLICK, fl_prevButtonClick);
    function fl_nextButtonClick(evt:MouseEvent):void
    {
    	fl_nextSlide();
    }
    function fl_prevButtonClick(evt:MouseEvent):void
    {
    	fl_prevSlide();
    }
    slideshowTimer.addEventListener(TimerEvent.TIMER, fl_slideShowNext);
    function fl_slideShowNext(evt:TimerEvent):void
    {
    	fl_nextSlide();
    }
    // END EVENTS
    
    // FUNCTIONS AND LOGIC =====
    function fl_parseImageXML(imageXML:XML):void
    {
    	var imagesNodes:XMLList = imageXML.children();
    	for(var i in imagesNodes)
    	{
    		var imgURL:String = imagesNodes[i];
    		var imgTitle:String = imagesNodes[i].attribute("title");
    		imageDP.addItem({label:imgTitle, source:imgURL, imgID:i});
    	}
    	imageTiles.dataProvider = imageDP;
    	imageHolder.imageLoader.source = imageDP.getItemAt(currentImageID).source;
    	title_txt.text = imageDP.getItemAt(currentImageID).label;
    }
    function fl_startSlideShow():void
    {
    	slideshowTimer.start();
    }
    function fl_pauseSlideShow():void
    {
    	slideshowTimer.stop();
    }
    function fl_nextSlide():void
    {
    	currentImageID++;
    	if(currentImageID >= imageDP.length)
    	{
    		currentImageID = 0;
    	}
    	if(transitionOn == true)
    	{
    		fl_doTransition();
    	}
    	imageHolder.imageLoader.source = imageDP.getItemAt(currentImageID).source;
    	title_txt.text = imageDP.getItemAt(currentImageID).label;
    }
    function fl_prevSlide():void
    {
    	currentImageID--;
    	if(currentImageID < 0)
    	{
    		currentImageID = imageDP.length-1;
    	}
    	if(transitionOn == true)
    	{
    		fl_doTransition();
    	}
    	imageHolder.imageLoader.source = imageDP.getItemAt(currentImageID).source;
    	title_txt.text = imageDP.getItemAt(currentImageID).label;
    }
    function fl_doTransition():void
    {
    	if(transitionType == "Blinds")
    	{
    		TransitionManager.start(imageHolder, {type:Blinds, direction:Transition.IN, duration:0.75});
    	} else if (transitionType == "Fade")
    	{
    		TransitionManager.start(imageHolder, {type:Fade, direction:Transition.IN, duration:0.25});
    	} else if (transitionType == "Fly")
    	{
    		TransitionManager.start(imageHolder, {type:Fly, direction:Transition.IN, duration:0.25});
    	} else if (transitionType == "Iris")
    	{
    		TransitionManager.start(imageHolder, {type:Iris, direction:Transition.IN, duration:0.25});
    	} else if (transitionType == "Photo")
    	{
    		TransitionManager.start(imageHolder, {type:Photo, direction:Transition.IN, duration:0.25});
    	} else if (transitionType == "PixelDissolve")
    	{
    		TransitionManager.start(imageHolder, {type:PixelDissolve, direction:Transition.IN, duration:0.25});
    	} else if (transitionType == "Rotate")
    	{
    		TransitionManager.start(imageHolder, {type:Rotate, direction:Transition.IN, duration:0.25});
    	} else if (transitionType == "Squeeze")
    	{
    		TransitionManager.start(imageHolder, {type:Squeeze, direction:Transition.IN, duration:0.25});
    	} else if (transitionType == "Wipe")
    	{
    		TransitionManager.start(imageHolder, {type:Wipe, direction:Transition.IN, duration:0.25});
    	} else if (transitionType == "Zoom")
    	{
    		TransitionManager.start(imageHolder, {type:Zoom, direction:Transition.IN, duration:0.25});
    	} else if (transitionType == "Random")
    	{
    		var randomNumber:Number = Math.round(Math.random()*9) + 1;
    		switch (randomNumber) {
    			case 1:
    				TransitionManager.start(imageHolder, {type:Blinds, direction:Transition.IN, duration:0.25});
    				break;
    			case 2:
    				TransitionManager.start(imageHolder, {type:Fade, direction:Transition.IN, duration:0.25});
    				break;
    			case 3:
    				TransitionManager.start(imageHolder, {type:Fly, direction:Transition.IN, duration:0.25});
    				break;
    			case 4:
    				TransitionManager.start(imageHolder, {type:Iris, direction:Transition.IN, duration:0.25});
    				break;
    			case 5:
    				TransitionManager.start(imageHolder, {type:Photo, direction:Transition.IN, duration:0.25});
    				break;
    			case 6:
    				TransitionManager.start(imageHolder, {type:PixelDissolve, direction:Transition.IN, duration:0.25});
    				break;
    			case 7:
    				TransitionManager.start(imageHolder, {type:Rotate, direction:Transition.IN, duration:0.25});
    				break;
    			case 8:
    				TransitionManager.start(imageHolder, {type:Squeeze, direction:Transition.IN, duration:0.25});
    				break;
    			case 9:
    				TransitionManager.start(imageHolder, {type:Wipe, direction:Transition.IN, duration:0.25});
    				break;
    			case 10:
    				TransitionManager.start(imageHolder, {type:Zoom, direction:Transition.IN, duration:0.25});
    				break;
    		}
    	} else
    	{
    		trace("error - transitionType not recognized");
    	}
    }
    if(autoStart == true)
    {
       fl_startSlideShow();
       playPauseToggle_mc.gotoAndStop("pause");
    }
    flash file: http://www.glass-ica.co.il/userfiles/flash/shir.html (Hebrew)
    Please help me figure it out...
    Thanks! Tal.
    Last edited by talooz; 01-25-2011 at 09:45 AM.


 

Posting Permissions

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