Results 1 to 4 of 4

Thread: AS2.0 - onRelease issue

  1. #1
    Join Date
    Aug 2008
    Posts
    2
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default AS2.0 - onRelease issue

    Hi there,
    First time poster here.

    On to my issue, I have some AS2.0 code pulling in values from XML into my swf and my function that I'm setting for my onRelease is being ran with no interaction at all. Its running in the loop and gives all the correct values, but it just runs on its own without clicking on the images/buttons for the onRelease to take effect. Here is my code for this:

    Code:
    var xmlData:XML = new XML();
    
    xmlData.ignoreWhite = true;
    
    xmlData.onLoad = function ()
    {
    	var nodes = this.firstChild.childNodes;
    	header.text = nodes[0].attributes.caption;
    	numOfItems = nodes.length;
    	for (var i=0;i<numOfItems;i++)
    	{
    		var t = home.attachMovie("item","item"+i,i+1);
    		var url = nodes[0].attributes.urlLoc + nodes[i].attributes.itemid;
    		t.angle = i * ((Math.PI*2)/numOfItems);
    		t.icon.inner.loadMovie(nodes[i].attributes.img);
    		t.onEnterFrame = mover;
    		t.icon.onRelease = released(url);
    	}
    }
    
    xmlData.load("flashFiles/items.xml");
    
    function released(e)
    {		
    	trace(e);
    	//getURL(e);
    }
    and the trace results from the code above:

    Code:
    http://www.myurllink.com/tmg_viewitem.asp?itemnbr=412
    http://www.myurllink.com/tmg_viewitem.asp?itemnbr=422
    http://www.myurllink.com/tmg_viewitem.asp?itemnbr=487
    http://www.myurllink.com/tmg_viewitem.asp?itemnbr=499
    http://www.myurllink.com/tmg_viewitem.asp?itemnbr=501
    http://www.myurllink.com/tmg_viewitem.asp?itemnbr=502
    http://www.myurllink.com/tmg_viewitem.asp?itemnbr=506
    http://www.myurllink.com/tmg_viewitem.asp?itemnbr=552
    http://www.myurllink.com/tmg_viewitem.asp?itemnbr=660
    http://www.myurllink.com/tmg_viewitem.asp?itemnbr=665
    The idea is that when clicked it will change the URL you're currently viewing in your browser. But I'm completely lost as to why the onRelease is running with no mouse interaction at all. Any help or ideas would be greatly appreciated.

    Thnx

  2. #2
    Join Date
    Mar 2007
    Location
    Currently: New York/Philadelphia
    Posts
    2,735
    Thanks
    3
    Thanked 519 Times in 507 Posts

    Default

    I don't know the technical reasoning here. Something about how the reference is really a variable that calls the function, instead of a call to the function directly. In any case, you can't supply a parameter using the syntax you are.

    So, replace t.icon.onRelease = released(url); with:
    Code:
    t.icon.onRelease = function() {
    	released(url);
    }
    Of course, url won't be available to the the onRelease function, so you'll have to do something like this:

    Code:
    t.icon.id = i;
    t.icon.onRelease = function() {
    	var url = nodes[0].attributes.urlLoc + nodes[this.id].attributes.itemid;
    	released(url);
    }

  3. The Following User Says Thank You to Medyman For This Useful Post:

    Tek81 (08-27-2008)

  4. #3
    Join Date
    Aug 2008
    Posts
    2
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default

    Thanks for the help, its working now.

    I'm either very slow at this or whatever, but the only way I could come up with to get the URL i wanted was to do If/If Else statements

    Code:
    t.icon.onRelease = function ()
    		{
    			if(this == _level0.item1.icon)
    			{
    				getURL(nodes[1].attributes.urlLoc, "_self");
    			}
    			else if(this == _level0.item2.icon)
    			{
    				getURL(nodes[2].attributes.urlLoc, "_self");
    			}
    			else if(this == _level0.item3.icon)
    			{
    				getURL(nodes[3].attributes.urlLoc, "_self");
    			}
                            and so on....

  5. #4
    Join Date
    Mar 2007
    Location
    Currently: New York/Philadelphia
    Posts
    2,735
    Thanks
    3
    Thanked 519 Times in 507 Posts

    Default

    I guessed you missed the small edit I made to the url variable.

    Code:
    var url = nodes[0].attributes.urlLoc + nodes[this.id].attributes.itemid;
    As long as you include the t.icon.id = i; outside the onRelease function, that will work. Bascially, what this is doing is assigning an arbitrary "id" property to each movieclip that is equal to the index of the for loop. So item0 has an id of 0, item1 has an id of 1, etc...

    Then, you can reference that number in the variable to target the XML node you want.

Bookmarks

Posting Permissions

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