15 Replies Latest reply on Oct 10, 2011 9:29 AM by J3DI13

    Need as2 help badly

    pumpy_lump

      Hello & Good Day!

       

      firstly i am a complete flash noob so please bear with me.

       

      I desperately need some guidance with a project i have taken over. Its really hard to describe but i shall try as best i can without causing to much confusion. Please view this link to see the project. Its still in the development stages.

       

      http://www.tayloredwright.com/server6/index.php?option=com_content&view=article&id=204&Ite mid=47

       

      You will see a image map that shows all the villages in the estate. Each village is linked to a flash movie of that village which shows all the details on the individual properties. Now when you select a property a pop up will appear showing its erf number, size & status (eg for-sale, sold etc). Now the problem im having is that i need to change it from showing the property size to showing the sale price. All that info is in the MySQL database but i don't know what to put in the action script to make it get that info.

       

      I will gladly mail any one the actionscript if they can help me.

        • 1. Re: Need as2 help badly
          Ned Murphy Adobe Community Professional & MVP

          The first place you need to deal with this is in the PHP file (or whatever file gets/delivers the data) to get it to acquire the data from the database and provide it to the Flash file.  If you can follow how that file sends along the Sold variable in its processing, you should be able to do almost the same thing in getting the price value delivered.

          • 2. Re: Need as2 help badly
            pumpy_lump Level 1

            Hi Ned

             

            Thank you for the response.

             

            I have looked at the php script and it has got a price string in it, my php is not to good either. Please find below the php code.

             

            <?php

             

                // Includes //

                include("../settings.php");

                include("../classes/class.config.php");

                include("../classes/class.mysql.php");

               

                // Connect to database

                mysql::connect();

               

                // Run query

                $qResult = mysql_query ("SELECT * FROM vcce_sites WHERE village = 6 ORDER BY id ASC");

                $nRows = mysql_num_rows($qResult);

                $rString ="&n=".$nRows;

                for ($i=0; $i< $nRows; $i++)

                {

                        // Pull it

                        $row = mysql_fetch_array($qResult);

                       

                        // Work out price

                        $price = strrev($row['price']);   

                        $price_array = str_split($price, 3);

                        foreach ($price_array as $value)

                        {

                            $p .= $value . ",";

                        }

                        $p = strrev($p);

                        if(substr($p,0,1) == ",") {$p = substr($p, 1);}

                       

                        // Work out vat

                        $vat = round($row['price'] * ($row['vat']/100));

                        $vat = strrev($vat);   

                        $vat_array = str_split($vat, 3);

                        foreach ($vat_array as $value)

                        {

                            $v .= $value . ",";

                        }

                        $v = strrev($v);

                        if(substr($v,0,1) == ",") {$v = substr($v, 1);}

                       

                        // Work out total

                        $cost = round($row['price'] * ($row['vat']/100)) + $row['price'];

                        $cost = strrev($cost);   

                        $cost_array = str_split($cost, 3);

                        foreach ($cost_array as $value)

                        {

                            $c .= $value . ",";

                        }

                        $c = strrev($c);

                        if(substr($c,0,1) == ",") {$c = substr($c, 1);}

                       

                        // Build String

                        if ($p==0) {$p = "";} else {$p = "R$p";}

                        if ($v==0) {$v = "";} else {$v = "R$v";}

                        if ($c==0) {$c = "";} else {$c = "R$c";}

                        $rString .="&amp;id".$i."=".$row['id']."&"."&erf".$i."=".$row['erf']."&"."&sold".$i."=".$row['sold ']."&"."&price".$i."=".$p."&"."&vat".$i."=".$v."&"."&total".$i."=".$c."&"."&size".$i."=".$ row['size'];

                       

                        // Reset Values

                        $p = "";

                        $v = "";

                        $c = "";

                }

                echo $rString."&";

             

            ?>

             

            Thanks Again

            • 3. Re: Need as2 help badly
              Ned Murphy Adobe Community Professional & MVP

              If you know that the php is sending the cost information, then you need to look at the code in the fla to see if it is extracting that value when it parses the data fed back to it.  What code do you have in the Flash file that reads what the php file sends?

              • 4. Re: Need as2 help badly
                pumpy_lump Level 1

                Here is all the code from the .fla

                 

                // Removes the Gradiant effect from the Datagrid component

                mx.controls.DataGrid.prototype.drawHeaderBG = function(Void)

                {

                    var mc:MovieClip = this.header_mc;

                    mc.clear();

                    var clr:Number = this.getStyle("headerColor");

                    var o:Object = this.__viewMetrics;

                    var tot:Number = Math.max(this.totalWidth, this.displayWidth+3);

                    mc.moveTo(o.left, o.top);

                    mc.beginFill(clr, 100);

                    mc.lineStyle(0, 0x000000, 0);

                    mc.lineTo(tot, o.top);

                    mc.lineTo(tot, this.__headerHeight+1);

                    mc.lineStyle(0, 0x000000, 0);

                    mc.lineTo(o.left, this.__headerHeight+1);

                    mc.lineStyle(0, 0x000000, 0);

                    mc.endFill();

                };

                 

                // Set the style for the datagrid component

                myDataGrid.setStyle("headerColor", 0xD4D0C8);

                myDataGrid.setStyle("borderStyle", "solid");

                myDataGrid.setStyle("color", 0xFFFFFF);

                myDataGrid.setStyle("alternatingRowColors", [0x1E4433, 0x2E5041]);

                import mx.styles.CSSStyleDeclaration;

                var headerStyles = new CSSStyleDeclaration();

                headerStyles.setStyle("color", 0x000000);

                headerStyles.setStyle("fontWeight","bold");

                myDataGrid.setStyle("headerStyle", headerStyles);

                 

                /* ----------------------------------------------------------------------------*/

                 

                 

                //// FUNCTIONS ////

                // Function to move the popup over the correct erf number when erf number is clicked

                L = {};

                L.click = function(obj)

                {

                    // Set position

                    popup._x = obj.thisx;

                    popup._y = obj.thisy;

                    popup.erf.htmlText = "<b>ERF: " + obj.number + "</b>";

                    popup.erf.htmlText = "<b>price: " + obj.number + "</b>";

                   

                    if (obj.stat == 0){popup.stat.htmlText = obj.stat = "Available"};

                    if (obj.stat == 1){popup.stat.htmlText = obj.stat = "Sold"};

                    if (obj.stat == 2){popup.stat.htmlText = obj.stat = "Re-Sale"};

                    photo.gotoAndStop("e" + obj.number);

                    //var n:Number = myDataGrid.length -1;

                    //info = myDataGrid.length;

                    myDataGrid.selectedIndex = null; // reset datagrid selected index

                    for (n=0; n<myDataGrid.length -1; n++)

                    {

                        if (myDataGrid.getItemAt(n)["Erf"] == obj.number)

                        {

                            myDataGrid.selectedIndex = n;

                        }

                    }

                   

                }

                 

                // Listener function to move the popup over the correct erf number when datagrid is clicked

                var dgListener:Object = new Object();

                dgListener.cellPress = function(evt_obj:Object)

                {

                    thisvalue = myDataGrid.getItemAt(evt_obj.itemIndex)["Erf"];

                    thissold = myDataGrid.getItemAt(evt_obj.itemIndex)["price"];

                    thissold = myDataGrid.getItemAt(evt_obj.itemIndex)["Status"];

                    thisx = eval("_root.e" + thisvalue);

                    thisy = eval("_root.e" + thisvalue);

                    // Reset position (For when there is no maching erf number)

                    popup._x = -9999;

                    popup._y = -9999;

                    // Set position

                    popup._x = thisx._x;

                    popup._y = thisx._y;

                    popup.erf.htmlText = "<b>" + thisvalue + "</b>";

                    popup.price.htmlText = "price: " + thissize;

                    popup.stat.htmlText = thissold;

                    info.text = thisvalue;

                    photo.gotoAndStop("e" + thisvalue);

                };

                 

                //// LOAD INFO ////

                // Load Data from mysql

                var my_lv:LoadVars = new LoadVars();           

                my_lv.onLoad = function(success:Boolean)

                {

                    //If success is true

                    if (success)

                    {

                        // Start Datagrid Array

                        var myDP:Array = new Array();

                       

                        // Loop it

                        var n:Number = new Number(my_lv.n); // 'n' is the number of records in the database

                        var i:Number = new Number();

                        for (i=0; i<n; i++)

                        {

                            // Set Sold Color on load

                            if (my_lv["sold"+i] == 1)

                            {

                                var colorful = new Color("_root.e" + my_lv["erf"+i]);

                                colorful.setRGB(0xCC0000);

                            }

                           

                            // Set available Color on load

                            if (my_lv["sold"+i] == 0)

                            {

                                var colorful = new Color("_root.e" + my_lv["erf"+i]);

                                colorful.setRGB(0xC1E3BB);;

                            }

                           

                            // Set resale Color on load

                            if (my_lv["sold"+i] == 2)

                            {

                                var colorful = new Color("_root.e" + my_lv["erf"+i]);

                                colorful.setRGB(0x9eb05e);

                            }

                           

                           

                 

                           

                            // Set Details to provide to popup

                            var erf = eval("_root.e" + my_lv["erf"+i]);

                            erf.number = my_lv["erf"+i];

                            erf.price = my_lv["price"+i];

                            erf.stat = my_lv["sold"+i];

                           

                            // Create Text Erf Numbers over all areas

                            if (erf.number != undefined)

                            {

                                var num:TextField = _root.createTextField("my_txt", i, erf._x-10, erf._y-8, 10, 10);

                                num.selectable = false;

                                num.text = erf.number;

                                num.autoSize = true;

                                var my_fmt:TextFormat = new TextFormat();

                                my_fmt.font = "Arial";

                                my_fmt.size = 8;

                                num.setTextFormat(my_fmt);

                            }

                           

                            // Create erfClip as function and add L.click listener to it.

                            var erfClip = eval("e" + my_lv["erf"+i]);

                            erfClip.onPress = function()

                            {

                                this.dispatchEvent({type:"click", number:this.number, stat:this.stat, thisx:this._x, thisy:this._y, erfsize:this.erfsize});

                            }

                            mx.events.EventDispatcher.initialize(erfClip);

                            erfClip.addEventListener("click", _root.L);

                           

                            // DATAGRID PART //

                            // Format my_lv string data

                            if (my_lv["sold"+i] == 0){s = "Available";}

                            if (my_lv["sold"+i] == 1){s = "Sold";}

                            if (my_lv["sold"+i] == 2){s = "Re-Sale";}

                           

                            // Create an array for the datagrid to work from

                            myDP.push({Erf:my_lv["erf"+i], Status:s, Price:my_lv["price"+i], Vat:my_lv["vat"+i], Total:my_lv["total"+i]});

                        }

                       

                        // Setup the Datagrid

                        myDataGrid.dataProvider = myDP; // array to use

                        myDataGrid.addEventListener("cellPress", dgListener); // Listener to use

                        myDataGrid.scrollbar

                        my_dg.setSize(490, 560);

                    }

                }

                 

                // Load Database file

                my_lv.load("src/sitemap_clubhouse.php");

                popup.swapDepths(9999);

                • 5. Re: Need as2 help badly
                  Ned Murphy Adobe Community Professional & MVP

                  I have not gone thru all the code... it is more helpful to only show the code relevant to the discussion.  REgardless, it is possible you are already processing the price, but then you destroy it when you reasssign it...

                   

                      thissold = myDataGrid.getItemAt(evt_obj.itemIndex)["price"]; 

                      thissold = myDataGrid.getItemAt(evt_obj.itemIndex)["Status"];

                   

                  Can you see how you get the price in the first line, but then get rid of it by assigning it the Status in the next?  Try getting rid of the second line

                  1 person found this helpful
                  • 6. Re: Need as2 help badly
                    pumpy_lump Level 1

                    I would delete the line but i need the status to show aswell. Its only the land size im replacing with the price.

                    • 7. Re: Need as2 help badly
                      Ned Murphy Adobe Community Professional & MVP

                      Then use another variable to hold the price... maybe call it "thisprice" instead of "thissold"

                      • 8. Re: Need as2 help badly
                        Ned Murphy Adobe Community Professional & MVP

                        Then a few lines later change the line ( popup.price.htmlText = "price: " + thissize; ) to be...

                         

                        popup.price.htmlText = "price: " + thisprice;

                        • 9. Re: Need as2 help badly
                          pumpy_lump Level 1

                          No that doesnt seem to be working, all im getting is it has changed the word "erf" on the pop up to the word "price"

                          • 11. Re: Need as2 help badly
                            Ned Murphy Adobe Community Professional & MVP

                            Change your code to the following and then indicate what the trace displays when you run it and click a location...

                             

                            dgListener.cellPress = function(evt_obj:Object)

                            {

                                thisvalue = myDataGrid.getItemAt(evt_obj.itemIndex)["Erf"];

                                thisprice = myDataGrid.getItemAt(evt_obj.itemIndex)["price"];

                               trace("thisprice = "+ thisprice);    // what does this display when you test?

                                thissold = myDataGrid.getItemAt(evt_obj.itemIndex)["Status"];

                                thisx = eval("_root.e" + thisvalue);

                                thisy = eval("_root.e" + thisvalue);

                                // Reset position (For when there is no maching erf number)

                                popup._x = -9999;

                                popup._y = -9999;

                                // Set position

                                popup._x = thisx._x;

                                popup._y = thisx._y;

                                popup.erf.htmlText = "<b>" + thisvalue + "</b>";

                                popup.price.htmlText = "price: " + thisprice;

                                popup.stat.htmlText = thissold;

                                info.text = thisvalue;

                                photo.gotoAndStop("e" + thisvalue);

                            };

                            1 person found this helpful
                            • 12. Re: Need as2 help badly
                              pumpy_lump Level 1

                              It hasnt changed anything from what i can see, How do i view what the trace displays?

                              • 13. Re: Need as2 help badly
                                Ned Murphy Adobe Community Professional & MVP

                                It should show up automatically in the output panel when you run the file and select an area to display its info. 

                                • 14. Re: Need as2 help badly
                                  Ned Murphy Adobe Community Professional & MVP

                                  Also, based on what I see later in the code, that line should be changed to use a capital P...

                                   

                                  thisprice= myDataGrid.getItemAt(evt_obj.itemIndex)["Price"];

                                  • 15. Re: Need as2 help badly
                                    J3DI13

                                    Hi Its me im at home & forgot my work login details, good thing ive got a private account

                                     

                                    I cant test the .fla file in flash for some unknown reason, it gives me a "Destination directory not exist".

                                    I have tried what you mentioned above but still no luck. I suppose this is what i get for taking over

                                    some one elses work.

                                     

                                    I dont know if this will help but on the original site www.vcce.co.za the 1 map "cascades" that still works

                                    has a "DataGrid" below the the map which displays all the relevant details eg. erf, price, size etc.

                                    The client doesnt want that anymore tho. So as you most probably have seen the code for that there.

                                     

                                    Thank you again for your help & assistance