Hi,

Maybe you can try to keep a Dictionary of Polygons outside your  
functions to be able to use them later, for example in your click  
events in the polygons.

Check this post:

http://groups.google.com/group/google-maps-api-for-flash/browse_thread/thread/faa51a6393e260c1/00610c50218e6a98?lnk=gst&q=Javier+de+la+Torre#00610c50218e6a98

Javier.

On Nov 7, 2008, at 11:23 AM, Goran wrote:

>
> Hi Pamela,
> thanks a lot for Your input.
> I want to make function that creates polygon and return its reference.
> Below is the function. I believe that key is in the addEventListener
> function. If I could get this function to return polygon then I could
> use this polygon for return object for makePolygonFromXML. In the code
> below I put polygon=polygonLoader.addEventListener(Event.COMPLETE,
> function(event:Event):Polygon  which doesn't work How do I make this
> function to return polygon reference?
>
> I tried to separate loader function (function that creates array of
> points) from function that creates polygon, but the problem is the
> same. addEventListener function must return array of points in order
> to use in function that creates polygon and I don't know how to make
> this function to return anything.
>
> Tnx.
> Goran
>
> private function
> makePolygonFromXML 
> (ID:String 
> ,name:String,xmlFile:String,col:Number,al:Number,wid:Number):Polygon
>       {
>
>               var polygonLoader:URLLoader
>               polygonLoader = new URLLoader()
>               var polygon:Polygon
>
> polygon=polygonLoader.addEventListener(Event.COMPLETE,
> function(event:Event):Polygon {
>                               var xmlCont:XML=new XML(polygonLoader.data);
>                               var points:Array = new Array;
>                               for each (var location:XML in xmlCont..*)
>                                         {
>                                           var LLfromXML:LatLng = new 
> LatLng([EMAIL PROTECTED],
> [EMAIL PROTECTED]);
>                                               points.push (LLfromXML)
>                                         }
>                               var polygonOptions:PolygonOptions= new 
> PolygonOptions
>                               var fillStyle:FillStyle = new FillStyle;
>                               fillStyle.alpha = al;
>                               fillStyle.color = col;
>                               polygonOptions.fillStyle = fillStyle;
>                               polygonOptions.tooltip="<font size='17'>" + 
> name + "</font>\n<font
> size='9' color='#726e00'>Kliknite za više podataka</font>"
>
>                               var strokeStyle:StrokeStyle = new StrokeStyle;
>                               strokeStyle.thickness=wid
>                               strokeStyle.color = 0x000000;
>                               strokeStyle.alpha=1
>                               polygonOptions.strokeStyle = strokeStyle
>
>
>                               var polygon:Polygon = new Polygon (points, 
> polygonOptions)
>
>                               polygon.addEventListener(MapMouseEvent.CLICK,
> function(e:MapMouseEvent):void
>                               {
>                                       navigateToURL(new 
> URLRequest("http://someurl"; + ID),'_self')
>                               })
>
>                               gMap.addOverlay(polygon);
>
>
>
>               })
>
>
>               var request:URLRequest=new URLRequest(xmlFile)
>
>               try
>               {
>                       polygonLoader.load(request);
>               }
>                       catch(error:Error)
>               {
>
>               }
>
> return polygon
>       }
>
> On 2 stu, 14:25, "pamela (Google Employee)" <[EMAIL PROTECTED]>
> wrote:
>> Hi Goran-
>> Did you figure it out? It might be simpler for you to put the loading
>> outside of the makePolygon function, and just pass the XML into the
>> makePolygon function. Then you wouldn't need to deal with the  
>> asynchronous
>> nature.
>>
>> If you still need help, please send over the full code for me to  
>> experiment
>> with.
>>
>> - pamela
>>
>>
>>
>> On Fri, Oct 17, 2008 at 7:34 PM, Goran <[EMAIL PROTECTED]> wrote:
>>
>>> Many thanks for your reply, but I am not sure what exactly do you  
>>> mean
>>> by that, could You show the example on my code? Thanks.
>>
>>> On 16 list, 01:58, "pamela (Google Employee)" <[EMAIL PROTECTED]>
>>> wrote:
>>>> Hi Goran-
>>
>>>> The Loader is an asynchronous function -  so the return statement  
>>>> is
>>>> reached before the loader finishes loading the file. One suggestion
>>>> would be to pass a callback function reference into the function  
>>>> and
>>>> call that when the polygon is actually created, passing the  
>>>> polygon to
>>>> it.
>>
>>>> - pamela
>>
>>>> On Tue, Oct 14, 2008 at 8:26 PM, Goran <[EMAIL PROTECTED]>  
>>>> wrote:
>>
>>>>> Please help, i'm stuck with this. I want to make function that  
>>>>> adds
>>>>> polygon from XML and RETURNS POLYGON OBJECT
>>
>>>>> (specPoly=makePolygonFromXML("data/xml/Opcine/desinic.xml",
>>>>> 0xfab000,0.3,2)
>>
>>>>> so I can reference it later to hide it or remove it, or use it  
>>>>> in a
>>>>> loop as an array of polygons.
>>
>>>>> function makePolygonFromXML works, it makes a polygon from XML  
>>>>> file
>>>>> but it doesn't return the polygon specified
>>>>> in function call, specPoly.hide() method doesn't work and all code
>>>>> after this method doesn't execute.
>>
>>>>> Any help would be much appreciated.
>>>>> Tnx in advance.
>>
>>>>> here is the code:
>>
>>>>> private var specPoly:Polygon //global variable
>>
>>>>> specPoly=makePolygonFromXML("data/xml/Opcine/desinic.xml",
>>>>> 0xfab000,0.3,2) //works
>>>>> specPoly.hide() //doesnt'work
>>
>>>>> private function
>>
>>> makePolygonFromXML 
>>> (xmlFile:String,col:Number,al:Number,wid:Number):Polygon
>>>>>        {
>>>>>                var polygon:Polygon
>>>>>                polygonLoader = new URLLoader()
>>>>>                polygonLoader.addEventListener(Event.COMPLETE,
>>>>> function(event:Event):void {
>>>>>                                var xmlCont:XML=new
>>> XML(polygonLoader.data);
>>>>>                            var points:Array = new Array;
>>>>>                                for each (var location:XML in
>>> xmlCont..*)
>>>>>                                          {
>>>>>                                            var LLfromXML:LatLng  
>>>>> = new
>>> LatLng([EMAIL PROTECTED],
>>>>> [EMAIL PROTECTED]);
>>>>>                                                points.push  
>>>>> (LLfromXML)
>>>>>                                          }
>>>>>                                var  
>>>>> polygonOptions:PolygonOptions= new
>>> PolygonOptions
>>>>>                                var fillStyle:FillStyle = new  
>>>>> FillStyle;
>>>>>                        fillStyle.alpha = al;
>>>>>                        fillStyle.color = col;
>>>>>                        polygonOptions.fillStyle = fillStyle;
>>
>>>>>                        var strokeStyle:StrokeStyle = new  
>>>>> StrokeStyle;
>>>>>                        strokeStyle.thickness=wid
>>>>>                        strokeStyle.color = 0x000000;
>>>>>                        strokeStyle.alpha=1
>>>>>                        polygonOptions.strokeStyle = strokeStyle
>>
>>>>>                                var polygon = new Polygon (points,
>>> polygonOptions)
>>>>>                                gMap.addOverlay(polygon);
>>
>>>>>                })
>>
>>>>>                var request:URLRequest=new URLRequest(xmlFile)
>>
>>>>>                try
>>>>>                {
>>>>>                        polygonLoader.load(request);
>>>>>                }
>>>>>                        catch(error:Error)
>>>>>                {
>>
>>>>>                }
>>>>> return polygon
>>>>> }- Sakrij citirani tekst -
>>
>>>> - Prikaži citirani tekst -- Sakrij citirani tekst -
>>
>> - Prikaži citirani tekst -
> >


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Google Maps API For Flash" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/google-maps-api-for-flash?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to