PHP User Warning: fetch_template() calls should be replaced by the vB_Template class. Template name: bbcode_highlight in ..../includes/functions.php on line 4197
Flash8 for loop, duplicate movieclip, and getURL problem
A Flash Developer Resource Site

Results 1 to 8 of 8

Thread: for loop, duplicate movieclip, and getURL problem

  1. #1
    Member
    Join Date
    Aug 2007
    Posts
    95

    Question for loop, duplicate movieclip, and getURL problem

    Hi,

    I have one movieclip which has onRelease function in the loop, but it isn't working for me properly. Maybe someone can help me with this.

    Here is my code:

    Actionscript Code:
    var dataXML:XML = new XML();
    dataXML.ignoreWhite = true;
    var url:String = "";

    dataXML.onLoad = function(success){
        if(success){
            var news:Array = dataXML.firstChild.firstChild.childNodes;
            for (i = 0; i < 9; i++) {
               
                                    url = news[i].childNodes[1].firstChild.nodeValue;

                   
                    mc_url.duplicateMovieClip("mc_url_new"+i, i);
                    _root["mc_url_new"+i]._x = 170;
                    _root["mc_url_new"+i]._y=i*mc_url._height;
           
                    _root["mc_url_new"+i].onRelease = function(){
                        this.getURL(url);
                    }

               
                trace(url);
            }
        }
        else{
            trace("didint load");
        }
    }
    dataXML.load("data.xml");

    Problem is, that all dynamically generated mc's have the same url which is the last in the xml file. But when I trace the code, all url's are loading successfully...

    I was wondering, that it could be the mc's depth problem, because dynamically generated last mc has the highest depth, but I can't figure it out how to solve this problem anyway...

  2. #2
    :
    Join Date
    Dec 2002
    Posts
    3,518
    Code:
    var dataXML:XML = new XML();
    dataXML.ignoreWhite = true;
    var url:String = "";
    dataXML.onLoad = function(success) {
    	if (success) {
    		var news:Array = dataXML.firstChild.firstChild.childNodes;
    		for (i=0; i<9; i++) {
    			var mc = mc_url.duplicateMovieClip("mc_url_new"+i, i);
    			mc._x = 170;
    			mc._y = i*mc_url._height;
    			mc.myurl = news[i].childNodes[1].firstChild.nodeValue;
    			mc.onRelease = function() {
    				this.getURL(this.myurl);
    			};
    		}
    	} else {
    		trace("didint load");
    	}
    };
    dataXML.load("data.xml");

  3. #3
    Member
    Join Date
    Aug 2007
    Posts
    95
    Thanks alot

    Completely solved problem

  4. #4
    Junior Member
    Join Date
    Apr 2010
    Posts
    3
    can somebody put actionscript 3 version for this ?

  5. #5
    :
    Join Date
    Dec 2002
    Posts
    3,518
    Please post your xml file format.

  6. #6
    Junior Member
    Join Date
    Apr 2010
    Posts
    3
    following is my xml format:

    <?xml version="1.0" encoding="utf-8"?>
    <data>
    <topics>
    <topic click="http://www.xyz.com/" title="-> Calculator: What would you save with a Hybrid?">Hybrid</topic>
    <topic click="http://www.abc.com/" title="-> Calculator: What would you save with a Hybrid?">Hybrid</topic>
    <topic click="http://www.google.com/" title="-> Calculator: What would you save with a Hybrid?">Hybrid</topic>
    <topic click="http://www.yahoo.com/" title="-> Calculator: What would you save with a Hybrid?">Hybrid</topic>
    </topics>
    </data>

  7. #7
    :
    Join Date
    Dec 2002
    Posts
    3,518
    Movie clip in library, export linkage class 'mc_url'
    Code:
    // AS3 code on main timeline
    var xmlData:XML;
    var loader:URLLoader = new URLLoader();
    loader.addEventListener(Event.COMPLETE, onComplete, false, 0, true);
    loader.addEventListener(IOErrorEvent.IO_ERROR, onIOError, false, 0, true);
    loader.load(new URLRequest("data.xml"));
    
    stop();
    function onComplete(evt:Event):void {
    	try {
    		xmlData=new XML(evt.target.data);
    		for (var i in xmlData.topics.topic) {
    			trace(xmlData.topics.topic[i]);
    			trace(xmlData.topics.topic[i].@click);
    			trace(xmlData.topics.topic[i].@title);
    			var mc = new mc_url();
    			mc.myurl=xmlData.topics.topic[i].@click.toString();
    			mc.x=170;
    			mc.y=i*mc.height;
    			mc.addEventListener(MouseEvent.MOUSE_UP, goURL);
    			addChild(mc);
    		}
    		loader.removeEventListener(Event.COMPLETE, onComplete);
    		loader.removeEventListener(IOErrorEvent.IO_ERROR, onIOError);
    		//
    	} catch (err:Error) {
    		trace("Could not parse loaded content and XML:\n" + err.message);
    	}
    }
    function goURL(evt:MouseEvent):void {
    	var url:URLRequest = new URLRequest(evt.currentTarget.myurl);
    	navigateToURL(url, "_blank");
    }
    function onIOError(evt:IOErrorEvent):void {
    	trace("Problem loading XML:\n" + evt.text);
    }

  8. #8
    Junior Member
    Join Date
    Apr 2010
    Posts
    3
    thanks a LOT

Tags for this Thread

Posting Permissions

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




Click Here to Expand Forum to Full Width

HTML5 Development Center