A Flash Developer Resource Site

Results 1 to 4 of 4

Thread: Parameter listener must be non-null??

  1. #1
    Senior Member
    Join Date
    Nov 2003
    Location
    N. Virginia
    Posts
    225

    Parameter listener must be non-null??

    Can't figure out why I'm getting this error:
    Error #2007: Parameter listener must be non-null.
    I have traced the xml, so I know the values are loading, so don't know why I"m getting a "non-null" error.

    The first value in the xml traces correctly, but then the error occurs.

    I only receive the error when I pass the popup argument to createImageHolders, and I don't know why... I"m a 3.0 newb.

    Code:
    import flash.events.MouseEvent;
    import flash.events.Event;
    import flash.events.EventDispatcher;
    import flash.display.MovieClip;
    import flash.display.Loader;
    import flash.net.URLRequest;
    import flash.xml.*;
    
    
    //xml loader
    var xmlLoader:URLLoader = new URLLoader();
    var xmlData:XML = new XML();
    var url:URLRequest;
    var fileURL:String;
    
    
    var popupURL:String;
    
    
    xmlLoader.addEventListener(Event.COMPLETE, LoadXML);
    xmlLoader.load(new URLRequest("images.xml"));
    var imageCounter:Number;
    
    //load xml file
    function LoadXML(e:Event):void {
    	xmlData = new XML(e.target.data);
    	imageCounter = xmlData.image.length();
    
    	//parse the xml
    	for (var j:Number = 0; j < imageCounter; j++) {
    		fileURL = xmlData.image.attribute("file")[j];
    		popupURL = xmlData.image.attribute("popup")[j];
    		var externalLdr:Loader = new Loader();
    		externalLdr.contentLoaderInfo.addEventListener(Event.INIT, createImageHolders(popupURL,e));
    		url = new URLRequest(fileURL);
    		externalLdr.load(url);
    	}
    }
    
    function createImageHolders(popup:String, e:Event) {
    	trace(popup);
    }

    Associated XML file:
    Code:
    <?xml version="1.0" encoding="UTF-8" ?>
    <root>
    	<image file="images/portfolio_images/01_dentist_small.jpg" popup="01_dentist.jpg"></image>
    	<image file="images/portfolio_images/02_medical_small.jpg" popup="02_medical.jpg"></image>
    	<image file="images/portfolio_images/03_paving_small.jpg" popup="03_paving.jpg"></image>
    	<image file="images/portfolio_images/04_travel_small.jpg" popup="04_travel.jpg"></image>
    	<image file="images/portfolio_images/05_contractor_small.jpg" popup="05_contractor.jpg"></image>
    	<image file="images/portfolio_images/06_vet_small.jpg" popup="06_vet.jpg"></image>
    	<image file="images/portfolio_images/07_lawyer_small.jpg" popup="07_lawyer.jpg"></image>
    	<image file="images/portfolio_images/08_restaurant_asian_small.jpg" popup="08_restaurant_asian.jpg"></image>
    	<image file="images/portfolio_images/09_restaurant_pizza_small.jpg" popup="09_restaurant_pizza.jpg"></image>
    </root>
    Last edited by bmarker; 06-15-2009 at 03:44 PM.

  2. #2
    Ө_ө sleepy mod
    Join Date
    Mar 2003
    Location
    Oregon, USA
    Posts
    2,441
    Comment out your code (start with the loop) and re-introduce one line at a time until it errors again, then trace out all the objects and properties in that line to make sure they're defined.

  3. #3
    Senior Member
    Join Date
    Nov 2003
    Location
    N. Virginia
    Posts
    225
    thanks nez

    I've been reading up, and I'm realizing I can't pass arguments to eventlisteners, so I don't know what I should be "commenting" out. But I'll post my solution. If anyone else has some true coding examples, it would be much appreciated.

  4. #4
    Will moderate for beer
    Join Date
    Apr 2007
    Location
    Austin, TX
    Posts
    6,801
    You can't directly pass arguments to listeners, true. But you can have a function which binds your arguments to a new listener function.
    Code:
    function createImageHolders(popup:String) {
    	trace(popup);
    }
    
    function makeCreateListener(popup:String):Function{
      return function(e:Event):void{
        createImageHolders(popup);
      }
    }
    Code:
    	externalLdr.contentLoaderInfo.addEventListener(Event.INIT, makeCreateListener(popupURL));
    The FunctionUtils package that I keep pimping in response to similar questions has utility functions that make this more or less transparent for you.
    http://cosmodro.me/blog/2008/aug/26/...ity-functions/

    Code:
    	externalLdr.contentLoaderInfo.addEventListener(Event.INIT, FunctionUtils.closurizeEventHandler(createImageHolders, popupURL));
    But you'd have to make createImageHolders take the event as the first parameter.

    Code:
    function createImageHolders(e:Event, popup:String) {
    	trace(popup);
    }

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