A Flash Developer Resource Site

Results 1 to 6 of 6

Thread: [RESOLVED] Ask : Map + PHP

  1. #1
    Junior Member
    Join Date
    Oct 2009
    Posts
    11

    resolved [RESOLVED] Ask : Map + PHP

    Dear all... It's have been a very long time since my first post in 2009

    After left flash behind for almost 4 years, my office ask me to make a simple GIS using flash, n i really got pain in the ass. I am very weak in scripting.
    After searching for hours in a couple days, i decided to make a kind of GIS using PHP n mySQL, with AS2 (the only script i ever used n i still didn't get it well til now LOL), with datagrid component
    So i made a trial before i m goin to make the real one. I make a couples data in PHP n show them in datagrid that can be update easily. But i still have problem with the map. My scenario is, when the datagrid show the data, the map on the left change its color according to the value shown in the "penduduk" column. I want the number ("no") be the ID to connect "penduduk" to map's movieclip.
    Then, when i update the "penduduk" data, the movieclip related to it change its color too..

    It's hard for me to describe it further, since english is not my main language. Hope the file attach below can explain more..
    Please download it here MapPHP2.zip

    Really need your help guys.. Coz time is keep running to the deadline

    Thx in advance
    Last edited by greg1806; 01-18-2016 at 02:14 AM. Reason: attach file

  2. #2
    . fruitbeard's Avatar
    Join Date
    Oct 2011
    Posts
    1,780
    Hi,

    I used a local array rather than your database data.

    Test it like so to see it working, then uncomment the orange lines and get rid of my 2 arrays at the beginning.

    PHP Code:
    stop();

    var 
    lv:LoadVars = new LoadVars();
    var 
    lv_update:LoadVars = new LoadVars();
    var 
    input:Array = new Array();

    var 
    kabupaten:Array = new Array(1224354667892356);
    var 
    penduduk:Array = new Array(1224354667892356);

    function 
    tampil_data()
    {
        
    //lv.onLoad = function()
        //{
            //var kabupaten:Array = lv.kabupaten.split(",");
            //var penduduk:Array = lv.penduduk.split(",");

            
    for (var i:Number 0penduduk.lengthi++)
            {
                var 
    colorful:Color = new Color(_root.allmap["map" + (1)]);
                var 
    pewarna:Number 0xFFCC00;
                
                if (
    penduduk[i] <= 50)
                {
                    
    pewarna 0xFF0000;
                }
                else if (
    penduduk[i] > 50)
                {
                    
    pewarna 0x006600;
                }
                
    colorful.setRGB(pewarna);
                
    input.addItem({no:(1), kabupaten:kabupaten[i], penduduk:penduduk[i]});
            }

            
    dg.dataProvider input;
        
    //};
        //lv.load("http://localhost/latihan/read_DG.php");
    }

    tampil_data();

    var 
    myListener:Object = new Object();
    myListener.cellPress = function(event)
    {
        
    no.text event.target.selectedItem['no'];
        
    kabupaten.text event.target.selectedItem['kabupaten'];
        
    penduduk.text event.target.selectedItem['penduduk'];
    };

    dg.addEventListener("cellPress",myListener);

    update.onRelease = function()
    {
        
    lv_update.no no.text;
        
    lv_update.kabupaten kabupaten.text;
        
    lv_update.penduduk penduduk.text;

        
    lv_update.sendAndLoad("http://localhost/latihan/update_datagrid.php",lv_update,post);
        
        
    play();
    }; 

  3. #3
    Junior Member
    Join Date
    Oct 2009
    Posts
    11
    Quote Originally Posted by fruitbeard View Post
    Hi,

    I used a local array rather than your database data.

    Test it like so to see it working, then uncomment the orange lines and get rid of my 2 arrays at the beginning.

    PHP Code:
    stop();

    var 
    lv:LoadVars = new LoadVars();
    var 
    lv_update:LoadVars = new LoadVars();
    var 
    input:Array = new Array();

    var 
    kabupaten:Array = new Array(1224354667892356);
    var 
    penduduk:Array = new Array(1224354667892356);

    function 
    tampil_data()
    {
        
    //lv.onLoad = function()
        //{
            //var kabupaten:Array = lv.kabupaten.split(",");
            //var penduduk:Array = lv.penduduk.split(",");

            
    for (var i:Number 0penduduk.lengthi++)
            {
                var 
    colorful:Color = new Color(_root.allmap["map" + (1)]);
                var 
    pewarna:Number 0xFFCC00;
                
                if (
    penduduk[i] <= 50)
                {
                    
    pewarna 0xFF0000;
                }
                else if (
    penduduk[i] > 50)
                {
                    
    pewarna 0x006600;
                }
                
    colorful.setRGB(pewarna);
                
    input.addItem({no:(1), kabupaten:kabupaten[i], penduduk:penduduk[i]});
            }

            
    dg.dataProvider input;
        
    //};
        //lv.load("http://localhost/latihan/read_DG.php");
    }

    tampil_data();

    var 
    myListener:Object = new Object();
    myListener.cellPress = function(event)
    {
        
    no.text event.target.selectedItem['no'];
        
    kabupaten.text event.target.selectedItem['kabupaten'];
        
    penduduk.text event.target.selectedItem['penduduk'];
    };

    dg.addEventListener("cellPress",myListener);

    update.onRelease = function()
    {
        
    lv_update.no no.text;
        
    lv_update.kabupaten kabupaten.text;
        
    lv_update.penduduk penduduk.text;

        
    lv_update.sendAndLoad("http://localhost/latihan/update_datagrid.php",lv_update,post);
        
        
    play();
    }; 
    Thx 4 the respond, mate. I tried to implement it to my script, n strangely my headache came worst n worst LOL. Still can't figure out how the map work with the database... I'm so bad in the script.. #sad

    If i use the local array, is the any way i can update it easily like mine before, i mean without editing the fla?

    Anyway, thank you so much for the respond, mate. It's great, & i realy appreciate it.. I hope i can hear from u soon for another solutions :-)
    Last edited by greg1806; 01-18-2016 at 11:38 AM.

  4. #4
    . fruitbeard's Avatar
    Join Date
    Oct 2011
    Posts
    1,780
    Hi,

    I can do it for you without the db as I don't have the time to set up a db and do the testing, you should be able to get it from this.

    firstly you need to rename the textboxes to "penduduks" and "kabupatens" or they clash witht the array names. just add s to eaxh text box name, the no.text is fine.

    PHP Code:
    stop();

    var 
    lv:LoadVars = new LoadVars();
    var 
    lv_update:LoadVars = new LoadVars();
    var 
    input:Array = new Array();

    var 
    selectedRow:Number;

    var 
    kabupaten:Array = new Array(1224354667892356);
    var 
    penduduk:Array = new Array(1224354667892356);

    function 
    tampil_data()
    {
        
    dg.removeAll();
        
    //lv.onLoad = function()
        //{
            //var kabupaten:Array = lv.kabupaten.split(",");
            //var penduduk:Array = lv.penduduk.split(",");

            
    for (var i:Number 0penduduk.lengthi++)
            {
                var 
    colorful:Color = new Color(_root.allmap["map" + (1)]);
                var 
    pewarna:Number 0xFFCC00;
                
                if (
    penduduk[i] <= 50)
                {
                    
    pewarna 0xFF0000;
                }
                else if (
    penduduk[i] > 50)
                {
                    
    pewarna 0x006600;
                }
                
    colorful.setRGB(pewarna);
                
                
    input.addItem({no:(1), kabupaten:kabupaten[i], penduduk:penduduk[i]});
            }

            
    dg.dataProvider input;
        
    //};
        //lv.load("http://localhost/latihan/read_DG.php");
    }

    tampil_data();

    var 
    myListener:Object = new Object();
    myListener.cellPress = function(event:Object)
    {
        
    no.text event.target.selectedItem['no'];
        
    penduduks.text event.target.selectedItem['penduduk'];
        
    kabupatens.text event.target.selectedItem['kabupaten'];
        
        
    selectedRow event.target.selectedIndex;
    };

    dg.addEventListener("cellPress",myListener);

    update.onRelease = function()
    {
        
    trace(selectedRow);
        
    penduduk.splice(selectedRow,1,Number(penduduks.text));
        
    kabupaten.splice(selectedRow,1,Number(kabupatens.text));
        
        
    tampil_data();
        
    //lv_update.no = no.text;
        //lv_update.kabupaten = kabupaten;
        //lv_update.penduduk = penduduk;

        //lv_update.sendAndLoad("http://localhost/latihan/update_datagrid.php",lv_update,post);
        
        //play();
    }; 
    You can always use xml instead or just a plain text file instead of a database, depends how and what you need/want.

    be good if you didnt edit your original answers so we know where we are.
    Last edited by fruitbeard; 01-18-2016 at 12:23 PM.

  5. #5
    Junior Member
    Join Date
    Oct 2009
    Posts
    11
    Quote Originally Posted by fruitbeard View Post
    Hi,

    I can do it for you without the db as I don't have the time to set up a db and do the testing, you should be able to get it from this.

    firstly you need to rename the textboxes to "penduduks" and "kabupatens" or they clash witht the array names. just add s to eaxh text box name, the no.text is fine.

    PHP Code:
    stop();

    var 
    lv:LoadVars = new LoadVars();
    var 
    lv_update:LoadVars = new LoadVars();
    var 
    input:Array = new Array();

    var 
    selectedRow:Number;

    var 
    kabupaten:Array = new Array(1224354667892356);
    var 
    penduduk:Array = new Array(1224354667892356);

    function 
    tampil_data()
    {
        
    dg.removeAll();
        
    //lv.onLoad = function()
        //{
            //var kabupaten:Array = lv.kabupaten.split(",");
            //var penduduk:Array = lv.penduduk.split(",");

            
    for (var i:Number 0penduduk.lengthi++)
            {
                var 
    colorful:Color = new Color(_root.allmap["map" + (1)]);
                var 
    pewarna:Number 0xFFCC00;
                
                if (
    penduduk[i] <= 50)
                {
                    
    pewarna 0xFF0000;
                }
                else if (
    penduduk[i] > 50)
                {
                    
    pewarna 0x006600;
                }
                
    colorful.setRGB(pewarna);
                
                
    input.addItem({no:(1), kabupaten:kabupaten[i], penduduk:penduduk[i]});
            }

            
    dg.dataProvider input;
        
    //};
        //lv.load("http://localhost/latihan/read_DG.php");
    }

    tampil_data();

    var 
    myListener:Object = new Object();
    myListener.cellPress = function(event:Object)
    {
        
    no.text event.target.selectedItem['no'];
        
    penduduks.text event.target.selectedItem['penduduk'];
        
    kabupatens.text event.target.selectedItem['kabupaten'];
        
        
    selectedRow event.target.selectedIndex;
    };

    dg.addEventListener("cellPress",myListener);

    update.onRelease = function()
    {
        
    trace(selectedRow);
        
    penduduk.splice(selectedRow,1,Number(penduduks.text));
        
    kabupaten.splice(selectedRow,1,Number(kabupatens.text));
        
        
    tampil_data();
        
    //lv_update.no = no.text;
        //lv_update.kabupaten = kabupaten;
        //lv_update.penduduk = penduduk;

        //lv_update.sendAndLoad("http://localhost/latihan/update_datagrid.php",lv_update,post);
        
        //play();
    }; 
    You can always use xml instead or just a plain text file instead of a database, depends how and what you need/want.

    be good if you didnt edit your original answers so we know where we are.
    Ha3, then u had read my original answer.. Feel so bad right now... Trully, I just felt not good to u, since i don't quite understand what u said in the post first. Then i realize that u gave me an example so i can figure out my self with my own script

    I intend to input many data there so i can use the app for quite long time since i can update it easily. So i really need to use the database there. But frankly, lack of scripting knowledge is the main barrier for me now..

    Ok, i'll try to figure it out, n i'll let u know if i can make it right. Thx , mate...

  6. #6
    Junior Member
    Join Date
    Oct 2009
    Posts
    11
    Hi fruitbeard, thank you so much for the great solutions. It works well like i want. Here are a little modifications to your script that make database works
    PHP Code:
    stop();

    var 
    lv:LoadVars = new LoadVars();
    var 
    lv_update:LoadVars = new LoadVars();
    var 
    input:Array = new Array();

    var 
    selectedRow:Number;

    //var kabupaten:Array = new Array(12, 24, 35, 46, 67, 89, 23, 56);
    //var penduduk:Array = new Array(12, 24, 35, 46, 67, 89, 23, 56);

    // test buat fungsi bikin interval dinamis dengan 4 kelas
    function getEqualBreaks(arrVar:Array,numClass:Number){
        var 
    breaks:Array = new Array();
        var 
    max:Number Math.max.apply(null,arrVar);
        var 
    min:Number Math.min.apply(null,arrVar);
        var 
    range:Number max min;
        var 
    step:Number Math.round(range/numClass);
        
        for (var 
    i:Number 0numClassi++)
        {
            
    breaks[i] = min + (step * (i+1) );
        }
        return 
    breaks;    
    }

    function 
    tampil_data()
    {
        
    dg.removeAll();
        
    lv.onLoad = function()
        {
            var 
    kabupaten:Array = lv.kabupaten.split(",");
            var 
    penduduk:Array = lv.penduduk.split(",");
            
    // test buat nyari max min
            
    var batasKelas:Array = getEqualBreaks(penduduk,4);
            
    trace(batasKelas);
            
            for (var 
    i:Number 0penduduk.lengthi++)
            {
                var 
    colorful:Color = new Color(_root.allmap["map" + (1)]);
                var 
    pewarna:Number 0xFFCC00;
                
                if (
    penduduk[i] <= 50){
                    
    pewarna 0xFF0000;
                }
                else if (
    penduduk[i] > 50)
                {
                    
    pewarna 0x006600;
                }
                
    colorful.setRGB(pewarna);
                
                
    input.addItem({no:(1), kabupaten:kabupaten[i], penduduk:penduduk[i]});
            }

            
    dg.dataProvider input;
        };
        
    lv.load("http://localhost/latihan/read_DG.php");
    }

    tampil_data();

    var 
    myListener:Object = new Object();
    myListener.cellPress = function(event:Object)
    {
        
    no.text event.target.selectedItem['no'];
        
    penduduks.text event.target.selectedItem['penduduk'];
        
    kabupatens.text event.target.selectedItem['kabupaten'];
        
        
    selectedRow event.target.selectedIndex;
    };

    dg.addEventListener("cellPress",myListener);

    update.onRelease = function()
    {
        
    trace(selectedRow);
        
    penduduk.splice(selectedRow,1,Number(penduduks.text));
        
    kabupaten.splice(selectedRow,1,Number(kabupatens.text));
        
        
    tampil_data();
        
    lv_update.no no.text;
        
    lv_update.kabupaten kabupatens;
        
    lv_update.penduduk penduduks.text;

        
    lv_update.sendAndLoad("http://localhost/latihan/update_datagrid.php",lv_update,post);
        
        
    play();
    }; 
    Thank you so much, mate.. You're great

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