Question

i am trying to add map in action script mobile app i have created xml for the layout, as the tags for the xml layout are predefined so i believe we cannot create custom tags, so i added that map using image tag but now the trouble is the mad components has disabled its scroll as well, no regrets that was suppose to be happen because i have created map under image, i tried to put the scrollVertical as well but that didn't work because that map was under image tag.

below is my code.

package
{
    import com.danielfreeman.madcomponents.*;
    import com.mapquest.*;
    import com.mapquest.services.geocode.*;
    import com.mapquest.tilemap.*;
    import com.mapquest.tilemap.controls.inputdevice.*;
    import com.mapquest.tilemap.controls.shadymeadow.*;
    import com.mapquest.tilemap.pois.*;

    import flash.display.Screen;
    import flash.display.Sprite;
    import flash.display.Stage;
    import flash.display.StageAlign;
    import flash.display.StageScaleMode;
    import flash.events.Event;
    import flash.geom.Point;
    import flash.geom.Rectangle;
    import flash.media.StageWebView;
    import flash.system.Capabilities;
    import flash.text.TextField;
    import flash.utils.flash_proxy;

    import mx.events.FlexEvent;



    public class map extends Sprite
    {   

        private static var alResults:Array;
    static  var   myMap:TileMap = new TileMap("my Key");
    static  var geocoder:Geocoder;


        public static const LAYOUT:XML = <scrollVertical background="#DADED4" >

                                    <imageLoader   id="placeholder"> </imageLoader  >

                </scrollVertical>;

        protected static var _message:UILabel;

        public static function initialize():void{


            var placeholder:UIImageLoader = UIImageLoader(UI.findViewById("placeholder"));
            placeholder.scrollRect
            placeholder.addChild(myMap);
            myMap.addControl(new SMLargeZoomControl());
            myMap.addControl(new SMViewControl());
            myMap.addControl(new MouseWheelZoomControl());

            myMap.size = new Size(300, 400);
            myMap.addControl(new SMLargeZoomControl());
            myMap.addControl(new SMViewControl());
            myMap.addControl(new MouseWheelZoomControl());

            // create a new TileMap object, passing your platform key
            geocoder = new Geocoder(myMap);

            geocoder.addEventListener(GeocoderEvent.GEOCODE_RESPONSE, onGeocodeResponse);
            geocoder.addEventListener(GeocoderEvent.GEOCODE_ERROR_EVENT, onGeocodeError);
            geocoder.addEventListener(GeocoderEvent.HTTP_ERROR_EVENT, onHttpError);
            doGeocode();
        }


        public function map()
        {
            super();

        }

        private static function onGeocodeResponse(e:GeocoderEvent):void {

            alResults = new Array();
            for each (var loc:GeocoderLocation in e.geocoderResponse.locations) {
                var o:Object = new Object();

                o.LatLng = loc.displayLatLng.lat + ", " + loc.displayLatLng.lng;
                o.GeocodeQuality = loc.geocodeQuality;
                o.GeocodeQualityCode = loc.geocodeQualityCode;

                alResults.push(o);
            }

            //this.dgResults.dataProvider = this.alResults;
            //this.vgrpResults.visible = true;
        }


        private static function doGeocode():void {    
            //remove all shapes form the map
            myMap.removeShapes();

            //use the default cursor
            //this.cursorManager.setBusyCursor();

            //make an array to hold the addresses
            var arrAddresses:Array = new Array();

            //push the addresses onto the array

            arrAddresses.push("placea");
            arrAddresses.push("place b");

            //call the geocoder object's geocode method, passing the array of addresses
            geocoder.geocode(arrAddresses);
        }

        private static function onGeocodeError(e:GeocoderEvent):void {
            //this.cursorManager.removeBusyCursor();
            makeErrorList("GEOCODER ERROR");
        }


        /*
        function to handle an error in the result
        */
        private static function onHttpError(e:GeocoderEvent):void {
            //this.cursorManager.removeBusyCursor();
            makeErrorList("HTTP ERROR");
        }



        /*
        function to make an array list to hold an error
        */
        private static function makeErrorList(s:String):void {
            var o:Object = new Object();
            o.LatLng = s;
            alResults.push(o);

            //this.dgResults.dataProvider = this.alResults;
            //this.vgrpResults.visible = true;
        }




    }
} 

has any one got any idea how do i achieve my goal :S help will be really appreciated.

Was it helpful?

Solution

Instead of using vertical i have used scrollXY than search for scroll see the following code

package
{
    import com.danielfreeman.extendedMadness.UIScrollXY;
    import com.danielfreeman.madcomponents.*;
    import com.mapquest.*;
    import com.mapquest.services.geocode.*;
    import com.mapquest.tilemap.*;
    import com.mapquest.tilemap.controls.inputdevice.*;
    import com.mapquest.tilemap.controls.shadymeadow.*;
    import com.mapquest.tilemap.pois.*;

    import flash.display.Screen;
    import flash.display.Sprite;
    import flash.display.Stage;
    import flash.display.StageAlign;
    import flash.display.StageScaleMode;
    import flash.events.Event;
    import flash.geom.Point;
    import flash.geom.Rectangle;
    import flash.media.StageWebView;
    import flash.system.Capabilities;
    import flash.text.TextField;
    import flash.utils.flash_proxy;

    import mx.events.FlexEvent;



    public class map extends Sprite
    {   

        private static var alResults:Array;
    static  var   myMap:TileMap = new TileMap("My Key");
    static  var geocoder:Geocoder;


        public static const LAYOUT:XML = 
            <scrollXY tapToScale="3.0" stageColour="#666666" scrollBarColour="#FFFFFF" width="480" height="640" border="false" id="scroller">
                                    <imageLoader   id="placeholder"> </imageLoader  >
</scrollXY>;

        protected static var _message:UILabel;

        public static function initialize():void{
            var scroller:UIScrollXY = UIScrollXY(UI.findViewById("scroller"));
            scroller.addChild(myMap);

            /*var placeholder:UIImageLoader = UIImageLoader(UI.findViewById("placeholder"));
            placeholder.scrollRect
            placeholder.addChild(myMap);
        */  myMap.addControl(new SMLargeZoomControl());
            myMap.addControl(new SMViewControl());
            myMap.addControl(new MouseWheelZoomControl());

            myMap.size = new Size(300, 400);
            myMap.addControl(new SMLargeZoomControl());
            myMap.addControl(new SMViewControl());
            myMap.addControl(new MouseWheelZoomControl());

            // create a new TileMap object, passing your platform key
            geocoder = new Geocoder(myMap);

            geocoder.addEventListener(GeocoderEvent.GEOCODE_RESPONSE, onGeocodeResponse);
            geocoder.addEventListener(GeocoderEvent.GEOCODE_ERROR_EVENT, onGeocodeError);
            geocoder.addEventListener(GeocoderEvent.HTTP_ERROR_EVENT, onHttpError);
            doGeocode();
        }


        public function map()
        {
            super();

        }

        private static function onGeocodeResponse(e:GeocoderEvent):void {

            alResults = new Array();
            for each (var loc:GeocoderLocation in e.geocoderResponse.locations) {
                var o:Object = new Object();

                o.LatLng = loc.displayLatLng.lat + ", " + loc.displayLatLng.lng;
                o.GeocodeQuality = loc.geocodeQuality;
                o.GeocodeQualityCode = loc.geocodeQualityCode;

                alResults.push(o);
            }

            //this.dgResults.dataProvider = this.alResults;
            //this.vgrpResults.visible = true;
        }


        private static function doGeocode():void {    
            //remove all shapes form the map
            myMap.removeShapes();

            //use the default cursor
            //this.cursorManager.setBusyCursor();

            //make an array to hold the addresses
            var arrAddresses:Array = new Array();

            //push the addresses onto the array

            arrAddresses.push("Loc1");
            arrAddresses.push("Loc2");

            //call the geocoder object's geocode method, passing the array of addresses
            geocoder.geocode(arrAddresses);
        }

        private static function onGeocodeError(e:GeocoderEvent):void {
            //this.cursorManager.removeBusyCursor();
            makeErrorList("GEOCODER ERROR");
        }


        /*
        function to handle an error in the result
        */
        private static function onHttpError(e:GeocoderEvent):void {
            //this.cursorManager.removeBusyCursor();
            makeErrorList("HTTP ERROR");
        }



        /*
        function to make an array list to hold an error
        */
        private static function makeErrorList(s:String):void {
            var o:Object = new Object();
            o.LatLng = s;
            alResults.push(o);

            //this.dgResults.dataProvider = this.alResults;
            //this.vgrpResults.visible = true;
        }




    }
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top