2 Replies Latest reply on Jan 31, 2011 1:21 AM by _spoboyle

    Combo Box and MySQL Entry

    willise414

      I have a combo box that has hard coded values of 1-6 inside of it. When the user selects one of these values (5 for example), I want the swf to place 5 entries into the database table. How can I do that in actionscript?

       

      I can do this easily if the user clicks on a button 5 times. But I can't figure out how to do this without clicking a button up to 6 times.

       

       

      Thanks for the help and advice!!

        • 1. Re: Combo Box and MySQL Entry
          Kumar Pratik

          Sorry but could not understand your question completely. Could you please elaborate?

          What value you have to update

          • 2. Re: Combo Box and MySQL Entry
            _spoboyle Level 4

            This is a SQLlite example in AIR but it will giv eyou the idea

             

            <?xml version="1.0" encoding="utf-8"?>
            <s:WindowedApplication xmlns:fx="http://ns.adobe.com/mxml/2009"
                                   xmlns:s="library://ns.adobe.com/flex/spark"
                                   xmlns:mx="library://ns.adobe.com/flex/mx"
                                   creationComplete="initApp()">
               
                <fx:Script>
                    <![CDATA[
                        import mx.collections.ArrayCollection;
                       
                        import spark.events.IndexChangeEvent;
                       
                        private static const data:ArrayCollection = new ArrayCollection([1, 2, 3, 4, 5, 6]);
                       
                        private var sqlConnection:SQLConnection;
                       
                        private function initApp():void
                        {
                            var dbFile:File = File.applicationStorageDirectory.resolvePath("database.db");
                            sqlConnection = new SQLConnection();
                            sqlConnection.addEventListener(SQLEvent.OPEN, onDBOpen);
                            sqlConnection.addEventListener(SQLErrorEvent.ERROR, onDBError);
                            sqlConnection.open(dbFile);
                        }
                       
                        private function onDBOpen(e:SQLEvent):void
                        {
                            trace("db open");
                            var statement:SQLStatement = new SQLStatement();
                            statement.sqlConnection = sqlConnection;
                            var query:String = "CREATE TABLE IF NOT EXISTS Entries " +
                                "(id INTEGER PRIMARY KEY AUTOINCREMENT, title TEXT)";
                            statement.text = query;
                           
                            try
                            {
                                statement.execute();
                            }
                            catch (error:SQLError)
                            {
                                trace("create users table error:" + error.details);
                            }
                        }
                       
                        private function onDBError(e:SQLErrorEvent):void
                        {
                            trace("db error");
                        }
                       
                        private function insertEntry():void
                        {
                            trace("inserting entry");
                            var statement:SQLStatement = new SQLStatement();
                            statement.sqlConnection = sqlConnection;
                            var query:String = "INSERT into Entries (title) VALUES (:title)";
                            statement.text = query;
                            statement.parameters[":title"] = "title";
                           
                            try
                            {
                                statement.execute();
                            }
                            catch (error:SQLError)
                            {
                                trace("insert entry error:" + error.details);
                            }
                        }

             

                        protected function comboBox_changeHandler(event:IndexChangeEvent):void
                        {
                            // TODO Auto-generated method stub
                            var number:int = comboBox.selectedItem;
                            for (var i:int = 0; i < number; i++)
                            {
                                insertEntry();
                            }
                        }

             

                    ]]>
                </fx:Script>
               
                <s:ComboBox id="comboBox" dataProvider="{data}" change="comboBox_changeHandler(event)"/>
            </s:WindowedApplication>