Normally I can figure out where exceptions are being thrown but this one is isn't so easy.I've got some pretty old code (see bottom of post) for creating a copy of a map used for pdf generation purposes. For example, in order to create an 8.5x11 landscape pdf, I regenerate my current onscreen map in another offscreen container of the correct dimensions, then send that over to some AlivePDF routines to generate the ouput pdf.This has all worked fine with all AGS/Flex API's up to 3.0. With 3.1 I get the following error sometime after the map copy in the new window is generated but before the map actually draws.
TypeError: Error #1009: Cannot access a property or method of a null object reference.
at com.esri.ags.layers::Layer/updateLayerIfInvalid()
at com.esri.ags.layers::Layer/updateDisplayList()
at mx.core::UIComponent/validateDisplayList()
at mx.managers::LayoutManager/validateDisplayList()
at mx.managers::LayoutManager/doPhasedInstantiation()
at mx.managers::LayoutManager/doPhasedInstantiationCallback()
I know the above snippet is pretty generic but I'm not sure what else to post here. The error seems to happen after the new container has the cloned map and right after I set the container.visible = true. My guess is that there is something borked in the layers of the new cloned map but since I don't really have a good understanding of how the cloning stuff works, I can't go much further with that.This has always been a kludge process to get PDF's out of these maps and I've never been happy with this process but it is what it is and it's baked into my apps. Basically, the cloning looks like this... I'm sure most folks have seen this setup before. If there is a better way (besides the new map template stuff, which won't work for my needs), please let me know. The below code creates a copy of the main app map, puts it in a bordercontainer and returns the bordercontainer with map. That bordercontainer is put in a titlewindow, off screen and then sent to the AlivePDF generation stuff.
registerClassAlias("com.esri.ags.Graphic", Graphic);
registerClassAlias("com.esri.ags.SpatialReference", SpatialReference);
registerClassAlias("com.esri.ags.FeatureSet", FeatureSet);
registerClassAlias("com.esri.ags.Map", Map);
registerClassAlias("com.esri.ags.layers.ArcGISDynamicMapServiceLayer", ArcGISDynamicMapServiceLayer);
registerClassAlias("com.esri.ags.layers.ArcGISTiledMapServiceLayer",ArcGISTiledMapServiceLayer);
registerClassAlias("com.esri.ags.layers.GraphicsLayer", GraphicsLayer);
registerClassAlias("com.esri.ags.layers.Layer", Layer);
registerClassAlias("com.esri.ags.geometry.MapPoint", MapPoint);
registerClassAlias("com.esri.ags.geometry.Multipoint", Multipoint);
registerClassAlias("com.esri.ags.geometry.Polygon", Polygon);
registerClassAlias("com.esri.ags.geometry.Polyline", Polyline);
registerClassAlias("com.esri.ags.geometry.Extent", Extent);
//Generic Symbols
registerClassAlias("com.esri.ags.symbols.CompositeSymbol",CompositeSymbol);
registerClassAlias("com.esri.ags.symbols.Symbol",Symbol);
//Point Symbols
registerClassAlias("com.esri.ags.symbols.SimpleMarkerSymbol",SimpleMarkerSymbol);
registerClassAlias("com.esri.ags.symbols.PictureMarkerSymbol",PictureMarkerSymbol);
registerClassAlias("com.esri.ags.symbols.TextSymbol",TextSymbol);
registerClassAlias("com.esri.ags.symbols.InfoSymbol",InfoSymbol);
//Line Symbols
registerClassAlias("com.esri.ags.symbosl.LineSymbol", LineSymbol);
registerClassAlias("com.esri.ags.symbols.SimpleLineSymbol", SimpleLineSymbol);
registerClassAlias("com.esri.ags.symbols.CartographicLineSymbol", CartographicLineSymbol);
//Polygon Symbols
registerClassAlias("com.esri.ags.symbols.SimpleFillSymbol",SimpleFillSymbol);
registerClassAlias("com.esri.ags.symbols.PictureFillSymbol", PictureFillSymbol);
for each(var oLayer:Layer in map.layers)
{
if (oLayer is ArcGISDynamicMapServiceLayer)
{
var cLayer:ArcGISDynamicMapServiceLayer = deepClone(oLayer) as ArcGISDynamicMapServiceLayer;
//cLayer.addEventListener(Event.COMPLETE,onLoadDone);
printMap.addLayer(cLayer);
}
else if (oLayer is ArcGISTiledMapServiceLayer)
{
var tLayer:ArcGISTiledMapServiceLayer = deepClone(oLayer) as ArcGISTiledMapServiceLayer;
/* var cLayer2:ArcGISDynamicMapServiceLayer = new ArcGISDynamicMapServiceLayer(tLayer.url);
cLayer2.id = tLayer.id;
cLayer2.imageFormat = "jpg";
cLayer2.addEventListener(Event.COMPLETE,onLoadDone);
printMap.addLayer(cLayer2); */
printMap.addLayer(tLayer);
}
else if (oLayer is GraphicsLayer)
{
var gLayer:GraphicsLayer = deepClone(oLayer) as GraphicsLayer;
printMap.addLayer(gLayer);
}
}
printMap.lods = null;
printMap.scale = map.scale;
printMap.scaleBarVisible = true;
printMap.panArrowsVisible = false;
printMap.zoomSliderVisible = false;
printMap.logoVisible = false;
printMap.useHandCursor = false;
var mp:MapPoint=new MapPoint(map.extent.center.x, map.extent.center.y)
//printMap.centerAt(mp);
printMap.extent=map.extent;
return componentPrintBorderContainer;
deepClone function
private function deepClone ( obj : * ) : *
{
var bytes : ByteArray = new ByteArray();
bytes.writeObject(obj);
bytes.position = 0;
return bytes.readObject();
}