PHP Classes

File: flashPash.firefly.demo.as

Recommend this page to a friend!
  Classes of Simon McKenna   flashPash   flashPash.firefly.demo.as   Download  
File: flashPash.firefly.demo.as
Role: Example script
Content type: text/plain
Description: Actionscript for Firefly demo
Class: flashPash
Database automation for Flash and PHP
Author: By
Last change:
Date: 21 years ago
Size: 43,335 bytes
 

Contents

Class file image Download
stop(); /*==-==-==-==-==-==-==-==-==-==-==-==-==-==-==+ | flashPash firefly demo | +==-==-==-==-==-==-==-==-==-==-==-==-==-==-==+ | version 1.0 *RC1* | | | | last update on 2003-07-07 by si*sshnug.com | | | | Copyright (c) 2002-2003, Simon Mckenna | | All rights reserved | +==-==-==-==-==-==-==-==-==-==-==-==-==-==-==+ | source best viewed with tab space set to 2 | +==-==-==-==-==-==-==-==-==-==-==-==-==-==-==*/ Stage.scaleMode = 'showAll'; /* for live demo on sshnug */ var rootLocation = 'http://flashpash.sshnug.com'; txtUser.text = 'user'; txtPass.text = 'userpass'; /* for release or local use */ var rootLocation = 'http://localhost/flashPash/demo'; txtUser.text = 'root'; txtPass.text = ''; katsiConnection = new LocalConnection(); /* first define the flashPash event methods to be called */ with ( demo_fp ) { onDebug = 'demo_fp_onDebug'; onStateChange = 'demo_fp_onStateChange'; beforeSelect = beforeInsert = beforeUpdate = beforeDelete = beforeSaveUpdates = beforeSQL = beforeMeta = 'demo_fp_beforeEvent'; afterSelect = 'demo_fp_afterSelect'; afterInsert = 'demo_fp_afterInsert'; afterUpdate = 'demo_fp_afterUpdate'; afterDelete = 'demo_fp_afterDelete'; afterSaveUpdates = 'demo_fp_afterSaveUpdates'; afterSQL = 'demo_fp_afterSQL'; afterMeta = 'demo_fp_afterMeta'; onSelectError = onInsertError = onUpdateError = onDeleteError = onSaveUpdatesError = onSQLerror = onMetaError = 'demo_fp_onError' } clientLog_fp.setFlashPashURL( demo_fp.flashPashURL ); serverLog_fp.setFlashPashURL( demo_fp.flashPashURL ); with ( cbxDatabaseType ) { addItemAt( 0, 'MySQL', 'mysql' ); addItemAt( 1, 'MySQL with transaction support', 'mysqlt' ); addItemAt( 2, 'Firebird', 'firebird' ); addItemAt( 3, 'Postgres', 'postgres' ); addItemAt( 4, 'Postgres v7 with limit support', 'postgres7' ); addItemAt( 5, 'Postgres v6.4 or earlier', 'postgres64' ); addItemAt( 6, 'Access/Jet ODBC DSN required', 'access' ); addItemAt( 7, 'ADO', 'ado' ); addItemAt( 8, 'ADO for Access', 'ado_access' ); addItemAt( 9, 'ADO for MS SQL', 'ado_mssql' ); addItemAt( 10, 'DB2', 'db2' ); addItemAt( 11, 'FoxPro', 'vfp' ); addItemAt( 12, 'FrontBase', 'fbsql' ); addItemAt( 13, 'Interbase Borland v6.5 or later', 'borland_ibase' ); addItemAt( 14, 'Interbase v6 or earlier', 'ibase' ); addItemAt( 15, 'Informix', 'informix' ); addItemAt( 16, 'Informix before v7.3', 'informix72' ); addItemAt( 17, 'MS SQL v7 or later', 'mssql' ); addItemAt( 18, 'MS SQL portable', 'mssqlpo' ); addItemAt( 19, 'Oracle v8 or v9', 'oci8' ); addItemAt( 20, 'Oracle portable', 'oci8po' ); addItemAt( 21, 'Oracle v8.05', 'oci805' ); addItemAt( 22, 'ODBC', 'odbc' ); addItemAt( 23, 'ODBC for MS SQL', 'odbc_mssql' ); addItemAt( 24, 'ODBC for Oracle', 'odbc_oracle' ); addItemAt( 25, 'SQL Anywhere', 'sqlanywhere' ); addItemAt( 26, 'Sybase', 'sybase' ); setSelectedIndex( 0 ); } /* same for flashPashStash */ /* with ( demo_fps ) { setDebug( true ); onDebug = 'demo_fp_onDebug'; onStateChange = 'demo_fp_onStateChange'; beforeDump = 'demo_fps_beforeDump'; afterDump = 'demo_fps_afterDump'; onDumpError = 'demo_fp_onError'; } */ /* define our global styles */ globalStyleFormat.shadow = 0x9DB9C8; globalStyleFormat.darkshadow = 0x558097; globalStyleFormat.scrollTrack = 0xCEDCE3; globalStyleFormat.highlight = 0x9DB9C8; globalStyleFormat.highlight3D = 0xCEDCE3; globalStyleFormat.applyChanges(); ckbGetDBNames.setStyleProperty( 'textSize', 10 ); cbxDatabaseName.removeAll(); cbxDatabaseName.addItem( 'flashpashtest', 'flashpashtest' ); cbxDatabaseName.setSelectedIndex( 0 ); cbxDatabaseName.setChangeHandler( 'cbxDatabaseName_click' ); /* set tab indexes */ cbxDatabaseType.tabIndex = 1; ckbGetDBNames.tabIndex = 2; cbxDatabaseName.tabIndex = 3; txtUser.tabIndex = 4; txtPass.tabIndex = 5; btnSelect.tabIndex = 6; btnResolve.tabIndex = 7; btnShowXMLdata.tabIndex = 8; btnClose.tabIndex = 9; firefly_nav.tabIndex = 10; firefly_grd.tabIndex = 11; btnOptions.tabIndex = 12; btnMeta.tabIndex = 13; btnGeneric.tabIndex = 14; btnStash.tabIndex = 15; btnHelp.tabIndex = 16; txtClientLog.tabIndex = 17; txtServerLog.tabIndex = 18; btnSaveClientLog.tabIndex = 19; btnClearClientLog.tabIndex = 20; btnClearServerLog.tabIndex = 21; btnSaveServerLog.tabIndex = 22; btnSelect.useHandCursor = true; btnResolve.useHandCursor = true; btnShowXMLdata.useHandCursor = true; btnClose.useHandCursor = true; btnOptions.useHandCursor = true; btnMeta.useHandCursor = true; btnGeneric.useHandCursor = true; btnStash.useHandCursor = true; btnHelp.useHandCursor = true; btnSaveClientLog.useHandCursor = true; btnClearClientLog.useHandCursor = true; btnClearServerLog.useHandCursor = true; btnSaveServerLog.useHandCursor = true; /* Writing code in the flash IDE wasn't a whole lot of fun, and for ease of distribution, the source for all the movie clips in this demo needs to be in a single file... so the code below sets up all non-root movie functions. probably isn't the most elegant way, but it works :) */ with ( options ) { ckbDebug.setChangeHandler( 'ckbDebug_click', _root ); ckbFlashPashEvents.setChangeHandler( 'ckbFlashPashEvents_click', _root ); ckbFireFlyEvents.setChangeHandler( 'ckbFireFlyEvents_click', _root ); ckbLimitRecordSet.setChangeHandler( 'ckbLimitRecordSet_click', _root ); } with ( meta ) { cbxMetaDataType.setSelectedIndex( 0 ); cbxMetaDataType.setChangeHandler( 'cbxMetaDataType_click', _root ); cbxMetaDataType_click(); btnDoMeta.setChangeHandler( 'btnDoMeta_click', _root ); btnDoMeta.useHandCursor = true; lblMetaResult._visible = false; txtMetaResult._visible = false; sbhMetaResult._visible = false; } with ( generic ) { btnDoSQL.setChangeHandler( 'btnDoSQL_click', _root ); btnDoSQL.useHandCursor = true; lblSQLresult._visible = false; lblSQLresultBug._visible = false; txtSQLresult._visible = false; sbhSQLresult._visible = false; } with ( current ) { btnInsert.setChangeHandler( 'btnInsert_click', _root ); btnUpdate.setChangeHandler( 'btnUpdate_click', _root ); btnDelete.setChangeHandler( 'btnDelete_click', _root ); btnInsert.useHandCursor = true; btnUpdate.useHandCursor = true; btnDelete.useHandCursor = true; } with ( stash ) { btnStashSelect.setChangeHandler( 'btnStashSelect_click', _root ); btnStashMeta.setChangeHandler( 'btnStashMeta_click', _root ); btnTrashStash.setChangeHandler( 'btnTrashStash_click', _root ); btnDumpStash.setChangeHandler( 'btnDumpStash_click', _root ); btnStashSelect.useHandCursor = true; btnStashMeta.useHandCursor = true; btnTrashStash.useHandCursor = true; btnDumpStash.useHandCursor = true; } ckbGetDBNames.setValue( false ); firefly_nav._width = 108; cbxMetaDataType_click(); ckbLimitRecordSet_click(); btnOptions_click(); firefly_ds_onCursorScrolled(); status = 'Click Select (open) to start'; function main() { with ( demo_fp ) { setDataSource( 'firefly_ds' ); setFlashPashURL( rootLocation + '/run.firefly.demo.php' ); setDebug( true ); setKey( 'table1', 't1integer', true ); setJoin( 'table1', 't1integer', demo_fp.FP_JOIN_INNER, 'table2', 't2key' ); setKey( 'table1', 't2key', true ); } options.txtURL.text = demo_fp.getFlashPashURL(); } /*==-==-==-==-==-==-==-==-==-==-==-==-==-==-==+ | flashPash 'before' type events | +==-==-==-==-==-==-==-==-==-==-==-==-==-==-==*/ /* 'before' type events are triggered from one function. 'after' type events have their own functions. 'error' type events are triggered from one function. To see how this is setup, check the event names in the demo_fp object. This demonstrates the different ways you call events. Note that you don't have to define the parameters of the event, they are optional. */ function demo_fp_beforeEvent( fpObj, fpEvent ) { switch ( fpEvent ) { case 'beforeSelect' : updateStatus( 'Selecting records from database...' ); break; case 'beforeInsert' : updateStatus( 'Inserting current record into database...' ); break; case 'beforeUpdate' : updateStatus( 'Updating current record...' ); break; case 'beforeDelete' : updateStatus( 'Deleting current record from database...' ); break; case 'beforeSaveUpdates' : updateStatus( 'Saving updates from dataset resolver...' ); break; case 'beforeMeta' : updateStatus( 'Retrieving meta-data from database...' ); break; case 'beforeSQL' : updateStatus( 'Running SQL query on server...' ); break; } updateDemo( demo_fp, 'demo> flashPash event - ' + fpEvent + chr( 10 )); processing.startWaiting(); txtPosition.text = ''; return true; } /*==-==-==-==-==-==-==-==-==-==-==-==-==-==-==+ | flashPash 'after' type events | +==-==-==-==-==-==-==-==-==-==-==-==-==-==-==*/ function demo_fp_afterSelect( fpObj, fpEvent, recordCount ) { /* create our lookup data */ lookup_xc.setData( "<dataPacket><row lookupkey=\"0\" lookup=\"Hello\" /><row lookupkey=\"1\"lookup=\"World\" /></dataPacket>" ); updateStatus(); updateDemo( demo_fp, 'demo> flashPash event - ' + fpEvent + ' - ' + recordCount + ' records returned' + chr( 10 )); katsiConnection.send( 'katsi', 'event', fpEvent, recordCount ); loadServerLog(); } function demo_fp_afterInsert( fpObj, fpEvent, recordCount ) { updateStatus(); updateDemo( demo_fp, 'demo> flashPash event - ' + fpEvent + ' - ' + recordCount + ' record inserted' + chr( 10 )); firefly_ds.purgeUpdates(); katsiConnection.send( 'katsi', 'event', fpEvent ); loadServerLog(); } function demo_fp_afterUpdate( fpObj, fpEvent, recordCount ) { updateStatus(); updateDemo( demo_fp, 'demo> flashPash event - ' + fpEvent + ' - ' + recordCount + ' record updated' + chr( 10 )); if ( recordCount > 0 ) { firefly_ds.post(); firefly_ds.purgeUpdates(); } katsiConnection.send( 'katsi', 'event', fpEvent ); loadServerLog(); } function demo_fp_afterDelete( fpObj, fpEvent, recordCount ) { updateStatus(); updateDemo( demo_fp, 'demo> flashPash event - ' + fpEvent + ' - ' + recordCount + ' record deleted' + chr( 10 )); if ( recordCount > 0 ) { firefly_ds.deleteRecord(); firefly_ds.purgeUpdates(); } katsiConnection.send( 'katsi', 'event', fpEvent ); loadServerLog(); } function demo_fp_afterSaveUpdates( fpObj, fpEvent, totalRecordCount, fpXMLresult ) { katsiConnection.send( 'katsi', 'event', fpEvent, totalRecordCount ); if (( totalRecordCount != null ) && ( firefly_xr.getDeltaPacket().getDeltaCount() > 0 )) { var rcd = totalRecordCount; ( rcd == 1 ) ? rcd += ' record affected' : rcd += ' records affected'; var dpc = firefly_xr.getDeltaPacket().getDeltaCount(); ( dpc == 1 ) ? dpc += ' delta packet' : dpc += ' delta packets'; updateStatus( 'flashPash happy! ' + rcd + ' from ' + dpc ); txtStatus.textColor = 0x0000FF; updateDemo( demo_fp, 'demo> flashPash event - ' + fpEvent + ' - result: ' + fpXMLresult.toString() + chr( 10 )); firefly_ds.purgeUpdates(); loadServerLog(); } else { updateDemo( demo_fp, 'demo> flashPash event - ' + fpEvent + chr( 10 )); updateStatus( 'No delta packets found so no action taken' ); processing.stopWaiting(); txtServerLog.text = ''; } } /* fpXMLresult is XML of what was returned from the flashPash PHP server */ function demo_fp_afterMeta( fpObj, fpEvent, recordCount, fpXMLresult ) { updateStatus(); updateDemo( demo_fp, 'demo> flashPash event - ' + fpEvent + ' - ' + recordCount + ' records returned' + chr( 10 )); if ( fpXMLresult.attributes[ demo_fp.FP_META_TYPE ] == demo_fp.FP_META_TYPE_DATABASES ) { cbxDatabaseName.removeAll(); var i = 1; while ( fpXMLresult.childNodes[ 0 ].attributes[ 'db' + i ] != undefined ) { cbxDatabaseName.addItemAt( i - 1, fpXMLresult.childNodes[ 0 ].attributes[ 'db' + i ], fpXMLresult.childNodes[ 0 ].attributes[ i ] ); i++; } if ( i <= 8 ) cbxDatabaseName.setRowCount( i ); else cbxDatabaseName.setRowCount( 8 ); cbxDatabaseName.setSelectedIndex( 0 ); txtStatus.textColor = 0x0000FF; if ( recordCount > 0 ) status += ' - look in database combo box'; else status += ' - unable to add to database list?'; } else if ( fpXMLresult.attributes[ demo_fp.FP_META_TYPE ] == demo_fp.FP_META_TYPE_TABLES ) { with ( meta ) { txtMetaInput.text = ''; cbxMetaDataTable.removeAll(); var i = 1; while ( fpXMLresult.childNodes[ 0 ].attributes[ 'table' + i ] != undefined ) { txtMetaInput.text += fpXMLresult.childNodes[ 0 ].attributes[ 'table' + i ] + chr( 10 ); cbxMetaDataTable.addItemAt( i - 1, fpXMLresult.childNodes[ 0 ].attributes[ 'table' + i ], fpXMLresult.childNodes[ 0 ].attributes[ 'table' + i ] ); i++; } if ( i <= 7 ) cbxMetaDataTable.setRowCount( i ); else cbxMetaDataTable.setRowCount( 8 ); cbxMetaDataTable.setSelectedIndex( 0 ) lblMetaInput.text = 'All tables in ' + cbxDatabaseName.getValue(); lblMetaInput._visible = true; txtMetaInput._visible = true; sbvMetaInput._visible = true; } } else if ( fpXMLresult.attributes[ demo_fp.FP_META_TYPE ] == demo_fp.FP_META_TYPE_COLUMNS ) { with ( meta ) { cbxMetaDataTable._visible = false; lblMetaInput.text = 'Columns in ' + cbxMetaDataTable.getValue(); var i = 1; while ( fpXMLresult.childNodes[ 0 ].attributes[ 'column' + i ] != undefined ) { txtMetaInput.text += fpXMLresult.childNodes[ 0 ].attributes[ 'column' + i ] + chr( 10 ); i++; } lblMetaInput._visible = true; txtMetaInput._visible = true; sbvMetaInput._visible = true; } } else if ( fpXMLresult.attributes[ demo_fp.FP_META_TYPE ] == demo_fp.FP_META_TYPE_SQL ) { with ( meta ) { txtMetaInput._height = 50; sbvMetaInput._height = 50; txtMetaResult.text = fpXMLresult.toString(); lblMetaResult._visible = true; txtMetaResult._visible = true; sbhMetaResult._visible = true; } firefly_grd.removeAllColumns(); firefly_grd.setDataSet( firefly_ds ); firefly_grd.bindColumns(); firefly_grd.updateDisplay(); } loadServerLog(); } function demo_fp_afterSQL( fpObj, fpEvent, recordCount, fpXMLresult ) { updateStatus(); updateDemo( demo_fp, 'demo> flashPash event - ' + fpEvent + chr( 10 )); with ( generic ) { txtSQLresult.text = ""; formatXML( txtSQLresult, fpXMLresult ); lblSQLresult._visible = true; lblSQLresultBug._visible = true; txtSQLresult._visible = true; sbhSQLresult._visible = true; } loadServerLog(); } /* display xml object - code modifed from "show" method created by Helen Triolo 4/2002 for actionscript-toolbox.com */ function formatXML( textFieldXML, node, spacer, parent ) { if ( node.firstChild != undefined ) { for ( var i = 0; i < node.childNodes.length; i++ ) { if ( node.childNodes[ i ].nodeName != undefined ) { textFieldXML.text += spacer + "<" + node.childNodes[ i ].nodeName; var a; for ( a in node.childNodes[ i ].attributes ) textFieldXML.text += " " + a + "=" + node.childNodes[ i ].attributes[ a ]; ( node.childNodes[ i ].firstChild.nodeValue == undefined ) ? textFieldXML.text += ">\n" : textFieldXML.text += ">"; } if ( node.childNodes[ i ].nodeValue != undefined ) textFieldXML.text += node.childNodes[ i ].nodeValue + "</" + parent + ">\n"; // show closing (non-text) tag if (( node.childNodes[ i ].nodeName != undefined ) && ( node.childNodes[ i ].nodeValue != undefined )) textFieldXML.text += spacer + "</" + node.childNodes[ i ].nodeName + ">"; // repeat for tags inside - go recursion..go recursion...go! if ( node.childNodes[ i ].firstChild != undefined ) formatXML( textFieldXML, node.childNodes[ i ], spacer + " ", node.childNodes[ i ].nodeName ); } } } /*==-==-==-==-==-==-==-==-==-==-==-==-==-==-==+ | other flashPash events | +==-==-==-==-==-==-==-==-==-==-==-==-==-==-==*/ function demo_fp_onDebug( fpObj, fpEvent, debugText ) { updateDemo( options.ckbDebug, debugText + chr( 10 )); } function demo_fp_onError( fpObj, fpEvent, error, errorText ) { /* you could switch( EventType ) and switch( SQLtype ) to find specific events instead of this general error */ updateStatus(); katsiConnection.send( 'katsi', 'event', fpEvent ); updateDemo( demo_fp, 'demo> flashPash event - ' + fpEvent + ' error: ' + error + ' errorText: ' + errorText + chr( 10 )); loadServerLog(); } function demo_fp_onStateChange( fpObj, fpEvent, oldState, newState, stateTimeTaken, bytesRead, bytesTotal ) { if ( oldState == newState ) { if ( oldState == demo_fp.FP_STATE_LOADING ) { updateDemo( demo_fp, 'demo> flashPash event - ' + fpEvent + ' - loading ' + bytesRead ); if ( bytesTotal == 0 ) updateDemo( demo_fp, ' bytes downloaded' + chr( 10 )); else updateDemo( demo_fp, ' out of ' + bytesTotal + ' bytes' + chr( 10 )); } else if ( oldState == demo_fp.FP_STATE_WAITING ) { updateDemo( demo_fp, 'demo> waiting - ' + demo_fp.time2string( stateTimeTaken ) + ' elapsed' + chr( 10 )); } } else { switch ( oldState ) { case demo_fp.FP_STATE_SLEEPING : var oldText = 'sleeping'; break; case demo_fp.FP_STATE_WORKING : var oldText = 'working'; break; case demo_fp.FP_STATE_WAITING : var oldText = 'waiting'; break; case demo_fp.FP_STATE_LOADING : var oldText = 'loading'; break; case demo_fp.FP_STATE_UPDATING : var oldText = 'updating'; break; } switch ( newState ) { case demo_fp.FP_STATE_SLEEPING : var newText = 'sleeping again'; break; case demo_fp.FP_STATE_WORKING : var newText = 'working'; break; case demo_fp.FP_STATE_WAITING : var newText = 'waiting'; break; case demo_fp.FP_STATE_LOADING : var newText = 'loading'; break; case demo_fp.FP_STATE_UPDATING : var newText = 'updating'; break; } updateDemo( demo_fp, 'demo> flashPash event - onStateChange ' ); updateDemo( demo_fp, 'from: ' + oldText + ' to ' + newText + chr( 10 )); } katsiConnection.send( 'katsi', 'event', fpEvent, oldState, newState ); } /*==-==-==-==-==-==-==-==-==-==-==-==-==-==-==+ | firefly events | +==-==-==-==-==-==-==-==-==-==-==-==-==-==-==*/ function firefly_ds_beforeOpen() { updateDemo( firefly_ds, 'demo> firefly event - dataset beforeOpen' + chr( 10 )); } function firefly_ds_beforeClose() { updateDemo( firefly_ds, 'demo> firefly event - dataset beforeClose' + chr( 10 )); } function firefly_ds_beforeInsert() { updateDemo( firefly_ds, 'demo> firefly event - dataset beforeInsert' + chr( 10 )); } function firefly_ds_beforePost() { updateDemo( firefly_ds, 'demo> firefly event - dataset beforePost' + chr( 10 )); } function firefly_ds_beforeDelete() { updateDemo( firefly_ds, 'demo> firefly event - dataset beforeDelete' + chr( 10 )); } function firefly_ds_afterOpen() { updateDemo( firefly_ds, 'demo> firefly event - dataset afterOpen (' + firefly_ds.getRecordCount( true ) + ')' + chr( 10 )); /* As the edit boxes, etc are in another movie, a bit of skullduggery is required here ;-) */ with ( current ) { integerField = firefly_ds.getFieldByName( edtIntegerField.fieldName ); realField = firefly_ds.getFieldByName( edtRealField.fieldName ); booleanField = firefly_ds.getFieldByName( ckbBooleanField.fieldName ); dateField = firefly_ds.getFieldByName( edtDateField.fieldName ); dateTimeField = firefly_ds.getFieldByName( edtDateTimeField.fieldName ); varcharField = firefly_ds.getFieldByName( txtVarcharField.fieldName ); edtIntegerField.setDataSet( firefly_ds ); edtIntegerField.setDataset( firefly_ds ); edtRealField.setDataSet( firefly_ds ); ckbBooleanField.setDataSet( firefly_ds ); edtDateField.setDataSet( firefly_ds ); edtDateTimeField.setDataSet( firefly_ds ); txtVarcharField.setDataSet( firefly_ds ); lucLookupField.setDataSet( firefly_ds ); lucLookupField.setLookupDataSet( lookup_ds ); edtIntegerField.setField( integerField ); edtRealField.setField( realField ); ckbBooleanField.setField( booleanField ); edtDateField.setField( dateField ); edtDateTimeField.setField( dateTimeField ); txtVarcharField.setField( varcharField ); edtIntegerField.updateDisplay(); edtRealField.updateDisplay(); ckbBooleanField.updateDisplay(); edtDateField.updateDisplay(); edtDateTimeField.updateDisplay(); txtVarcharField.updateDisplay(); } } function firefly_ds_afterInsert() { updateDemo( firefly_ds, 'demo> firefly event - dataset afterInsert' + chr( 10 )); } function firefly_ds_afterDelete() { updateDemo( firefly_ds, 'demo> firefly event - dataset afterDelete' + chr( 10 )); } function firefly_ds_afterPost() { updateDemo( firefly_ds, 'demo> firefly event - dataset afterPost' + chr( 10 )); } function firefly_ds_afterClose() { updateDemo( firefly_ds, 'demo> firefly event - dataset afterClose' + chr( 10 )); } function firefly_ds_onCalculateFields() { //Too much overhead with large recordsets! //updateDemo( firefly_ds, 'demo> firefly event - dataset onCalculateFields' + chr( 10 )); } function firefly_ds_onFilterRecord() { updateDemo( firefly_ds, 'demo> firefly event - dataset onFilterRecord' + chr( 10 )); } function firefly_ds_onNewRecord() { var key = String( demo_fp.now() ).substr( 6 ); updateDemo( firefly_ds, 'demo> firefly event - dataset onNewRecord - setting key as ' + key + chr( 10 )); firefly_ds.getFieldByName( 't1integer' ).setAsNumber( key ); firefly_ds.getFieldByName( 't2key' ).setAsNumber( key ); } function firefly_ds_onCursorScrolled() { if ( firefly_ds.isActive() ) { var recNum = firefly_ds.getCurrentRecordId() + 1; var recTotal = firefly_ds.getRecordCount( true ); if ( recTotal > 0 ) txtPosition.text = 'Record ' + recNum + ' of ' + recTotal; else txtPosition.text = 'No records'; switch ( firefly_ds.getMode() ) { case FxDataSetClass.Unknown : txtPosition.text += ' [Unknown mode]'; break; case FxDataSetClass.BrowseMode : txtPosition.text += ' [Browse mode]'; break; case FxDataSetClass.EditMode : txtPosition.text += ' [Edit mode]'; break; case FxDataSetClass.InsertMode : txtPosition.text += ' [Insert mode]'; break; case FxDataSetClass.InsertOrEditMode : txtPosition.text += ' [Insert/Edit mode]'; break; case FxDataSetClass.InactiveMode : txtPosition.text += ' [Inactive mode]'; break; case FxDataSetClass.DeleteMode : txtPosition.text += ' [Delete mode]'; break; } } else { txtPosition.text = 'No records [dataset inactive]'; } } function firefly_ds_onRecordCountChange() { updateDemo( firefly_ds, 'demo> firefly event - dataset onRecordCountChange' + chr( 10 )); } function firefly_ds_onSchemaLoaded() { updateDemo( firefly_ds, 'demo> firefly event - dataset onSchemaLoaded' + chr( 10 )); } function firefly_ds_onError(dataset, message, kind) { var kindDescription = null; switch ( kind ) { case FxDataSetClass.ekIndex : kindDescription = 'Index'; break; case FxDataSetClass.ekDelete : kindDescription = 'Delete'; break; case FxDataSetClass.ekModify : kindDescription = 'Modify'; break; case FxDataSetClass.ekInsert : kindDescription = 'Insert'; break; case FxDataSetClass.ekOpen : kindDescription = 'Open'; break; case FxDataSetClass.ekField : kindDescription = 'Field'; break; case FxDataSetClass.ekLookup : kindDescription = 'Lookup'; break; } if ( kindDescription != null ) updateDemo( firefly_ds_onError, 'demo> firefly event - dataset ' + dataset._name + ' onError kind: ' + kindDescription + ' - ' + message + chr( 10 ) ); } function firefly_xc_beforeClose() { updateDemo( firefly_xc, 'demo> firefly event - connector beforeClose' + chr( 10 )); } function firefly_xc_beforeOpen() { updateDemo( firefly_xc, 'demo> firefly event - connector beforeOpen' + chr( 10 )); } function firefly_xc_afterOpen() { updateDemo( firefly_xc, 'demo> firefly event - connector afterOpen' + chr( 10 )); } function firefly_xc_afterClose() { updateDemo( firefly_xc, 'demo> firefly event - connector afterClose' + chr( 10 )); updateStatus( 'Dataset closed' ); } function firefly_xc_onStatus( connector, status ) { if ( status.containsError() ) { updateDemo( firefly_xc, 'demo> firefly event - connector ' + connector._name + ' onStatus' + chr( 10 )); var statusItem; for ( var i=0; i < status.getStatusCount(); i++ ) { statusItem = status.getStatusAt( i ); updateDemo( firefly_xc, 'status> level: ' + status.level+ ' code: ' + status.code + ' source: ' + status.source + ' desc: ' + status.description + chr( 10 )); } } } function firefly_xr_beforeApplyDelta() { updateDemo( firefly_xr, 'demo> firefly event - resolver beforeApplyDelta' + chr( 10 )); } function firefly_xr_afterApplyDelta() { updateDemo( firefly_xr, 'demo> firefly event - resolver afterApplyDelta' + chr( 10 )); } function firefly_xr_onResults() { updateDemo( firefly_xr, 'demo> firefly event - resolver onResults' + chr( 10 )); } function firefly_xr_onStatus( resolver, status ) { if ( status.containsError() ) { updateDemo( firefly_xr, 'demo> firefly event - resolver ' + resolver._name + ' onStatus' + chr( 10 )); var statusItem; for( var i=0; i < status.getStatusCount(); i++ ) { statusItem = status.getStatusAt( i ); updateDemo( firefly_xr, 'status> level: ' + status.level+ ' code: ' + status.code + ' source: ' + status.source + ' desc: ' + status.description + chr( 10 )); } } } function firefly_grd_onRowClicked( grid, row ) { updateDemo( firefly_grd, 'demo> firefly event - onRowClicked for grid: ' + grid + ' row: ' + row + chr( 10 )); } function firefly_grd_onRowDblClicked( grid, row ) { updateDemo( firefly_grd, 'demo> firefly event - onRowDblClicked for grid: ' + grid + ' row: ' + row + chr( 10 )); } function firefly_grd_onColumnsLoaded( grid ) { var i = 0; var column = grid.getColumnAt( i ); while ( column != undefined ) { column.setStyleProperty( 'headerFace', globalStyleFormat.highlight3D ); i++; column = grid.getColumnAt( i ); } updateDemo( firefly_grd, 'demo> firefly event - onColumnsLoaded for grid: ' + grid._name + chr( 10 )); } function firefly_grd_onColumnSized( grid, column, width ) { updateDemo( firefly_grd, 'demo> firefly event - onColumnSized for grid: ' + grid._name + ' width: ' + width + chr( 10 )); } function firefly_grd_onColumnSorted( grid, column, field ) { updateDemo( firefly_grd, 'demo> firefly event - onColumnSorted for grid: ' + grid._name + chr( 10 )); } function firefly_grd_onDataLoaded( grid ) { updateDemo( firefly_grd, 'demo> firefly event - onDataLoaded for grid: ' + grid._name + chr( 10 )); } function firefly_grd_onInitEditor( grid, column, editor ) { updateDemo( firefly_grd, 'demo> firefly event - onInitializeEditor for grid: ' + grid._name + ' editor: ' + editor + chr( 10 )); } function firefly_grd_onFocusEditor( grid, column, editor ) { updateDemo( firefly_grd, 'demo> firefly event - onFocusEditor for grid: ' + grid._name + ' editor: ' + editor + chr( 10 )); } function firefly_grd_onHyperClick( grid, column, field) { updateDemo( firefly_grd, 'demo> firefly event - onHyperlinkClicked for grid: ' + grid._name + chr( 10 )); } /*==-==-==-==-==-==-==-==-==-==-==-==-==-==-==+ | demo form events and functions | +==-==-==-==-==-==-==-==-==-==-==-==-==-==-==*/ function cbxDatabaseType_click() { if (( txtUser.text.length > 0 )) { setup( demo_fp ); if ( ckbGetDBNames.getValue() ) demo_fp.doMeta( demo_fp.FP_META_TYPE_DATABASES ); } } function cbxDatabaseName_click() { if ( meta._visible ) if ( meta.cbxMetaDataTable.getValue() == demo_fp.FP_META_TYPE_TABLES ) btnDoMeta.setLabel( 'Get tables in ' + cbxDatabaseName.getValue() ); } function btnSelect_click() { setup( demo_fp ); if ( options.ckbLimitRecordSet.getValue() && ( Number( options.txtRecordLimit.text ) > 0 )) { demo_fp.setRecordLimit( options.txtRecordLimit.text ); demo_fp.setLimitFrom( Number( options.txtLimitFrom.text )); } else { demo_fp.setRecordLimit( null ); demo_fp.setLimitFrom( null ); } firefly_grd.setDataSet( firefly_ds ); if ( options.txtSQLcondition.length > 0 ) demo_fp.doSelect( options.txtSQLcondition.text ); else demo_fp.doSelect(); } function btnResolve_click() { if ( firefly_ds.isActive() ) { setup( demo_fp ); demo_fp.doSaveUpdates( true ); } else updateStatus( 'No updates possible as dataset is closed' ); } function btnShowXMLdata_click() { getUrl( rootLocation + '/load.flashPash.log.php?logfile=log.firefly.demo.xml', '_blank' ); } function btnClose_click() { if ( firefly_ds.isActive() ) firefly_ds.close(); else updateStatus( 'Dataset already closed' ); } btnFireFly.onRelease = function() { getUrl( 'http://www.macromedia.com/software/dataconnection/', '_blank' ); } btnPHP.onRelease = function() { getUrl( 'http://www.php.net', '_blank' ); } btnADOdb.onRelease = function() { getUrl( 'http://php.weblogs.com/adodb', '_blank' ); } function btnSaveClientLog_click() { setup( clientLog_fp ); clientLog_fp.doSQL( 'INSERT INTO debugLog VALUES ("' + currentDate() + '", "Client", "' + txtClientLog.text + '")' ); } function btnSaveServerLog_click() { setup( serverLog_fp ); serverLog_fp.doSQL( 'INSERT INTO debugLog VALUES ("' + currentDate() + '", "Server", "' + txtServerLog.text + '")' ); } function btnClearClientLog_click() { txtClientLog.text = ''; btnSaveClientLog.setLabel( 'Save client log' ); } function btnClearServerLog_click() { txtServerLog.text = ''; btnSaveServerLog.setLabel( 'Save server log' ); } function clientLog_fp_afterSQL() { btnSaveClientLog.setLabel( 'Log saved' ); txtServerLog.text = ''; } function serverLog_fp_afterSQL() { btnSaveServerLog.setLabel( 'Log saved' ); txtServerLog.text = ''; } function clientLog_fp_SQLerror() { btnSaveClientLog.setLabel( 'Save error' ); txtServerLog.text = ''; } function serverLog_fp_SQLerror() { btnSaveServerLog.setLabel( 'Save error' ); txtServerLog.text = ''; } function currentDate( notTime ) { var dt = new Date(); if ( notTime === true ) return dt.getFullYear()+'-'+( dt.getMonth()+1 )+'-'+dt.getDate(); else return dt.getFullYear()+'-'+( dt.getMonth()+1 )+'-'+dt.getDate()+' '+dt.getHours()+':'+dt.getMinutes()+':'+dt.getSeconds(); } function updateStatus( flashPashStatus ) { if ( demo_fp.error == demo_fp.FP_ERROR_NONE ) { if ( flashPashStatus.length > 0 ) { txtStatus.textColor = 0x426573; status = flashPashStatus; } else { txtStatus.textColor = 0x0000FF; status = 'flashPash happy! ' + demo_fp.recordCount; ( demo_fp.recordCount == 1 ) ? status += ' record affected' : status += ' records affected'; } } else { if ( flashPashStatus.length > 0 ) { txtStatus.textColor = 0x426573; status = flashPashStatus; } else { txtStatus.textColor = 0xFF0000; status = 'oh no! error ' + demo_fp.error + ' ' + demo_fp.errorText; } } updateAfterEvent(); } function updateDemo( eventObject, message ) { if ( eventObject == options.ckbDebug ) var updateLog = options.ckbDebug.getValue(); else if ( eventObject == demo_fp ) var updateLog = options.ckbFlashPashEvents.getValue(); else /* firefly event */ var updateLog = options.ckbFireFlyEvents.getValue(); if ( updateLog ) { txtClientLog.text += message; txtClientLog.scroll = txtClientLog.maxscroll; } deltaCount = firefly_xr.getDeltaPacket().getDeltaCount(); if (( deltaCount == undefined ) || ( deltaCount == null)) deltaCount = 0; ( deltaCount > 0 ) ? btnResolve.setLabel( 'Save ' + deltaCount + ' updates' ) : btnResolve.setLabel( 'Save updates' ); firefly_ds_onCursorScrolled(); } function updateLogLabels() { if ( options.ckbDebug.getValue() ) { lblClientLog.text = 'flashPash MX client debug'; lblServerLog.text = 'flashPash PHP server debug log'; } else { lblClientLog.text = ''; lblServerLog.text = ''; } if ( options.ckbFlashPashEvents.getValue() ) { if ( lblClientLog.text != '' ) lblClientLog.text += ' + '; if ( options.ckbFireFlyEvents.getValue() ) lblClientLog.text += 'flashPash & firefly events'; else lblClientLog.text += 'flashPash events'; } else if ( options.ckbFireFlyEvents.getValue() ) { if ( lblClientLog.text != '' ) lblClientLog.text += ' + '; lblClientLog.text += 'firefly events'; } if ( lblClientLog.text == '' ) lblClientLog.text = 'No client-side debugging messages displayed'; if ( lblServerLog.text == '' ) lblServerLog.text = 'No server-side debugging messages displayed'; } function loadServerLog() { if ( options.ckbDebug.getValue() ) { /* If error has occured, check what caused it ( >=50 == Server <50 == Client ) */ /* Do not load log if client error as chances are it's the previously log!!! */ if (( demo_fp.error > 0 ) && ( demo_fp.error < 50 )) { txtServerLog.text = 'demo> flashPash server log not loaded due to client error'; } else { txtServerLog.text = 'request completed...loading server log...'; btnClearServerLog.setLabel( 'loading server log...' ); serverLog = new LoadVars(); serverLog.onLoad = whenLoaded; serverLog.sendAndLoad( rootLocation + '/load.flashPash.log.php?logfile=log.firefly.demo.txt', serverLog ); } } processing.stopWaiting(); } function whenLoaded( ok ) { if ( ok && serverLog.loaded ) { /* for reasons unknown, LoadVars.toString appends &onLoad=[type Function] so we remove it */ logText = unescape( serverLog.toString() ); txtServerLog.text = logText.substring( 0, ( logText.length - 23 )); txtServerLog.scroll = 0; delete logText; delete serverLog; } else { txtServerLog.text = ''; } btnClearServerLog.setLabel( 'Clear server log' ); } function setup( flashPashObject ) { if ( flashPashObject == demo_fp ) { btnSaveClientLog.setLabel( 'Save client log' ); btnSaveServerLog.setLabel( 'Save server log' ); txtClientLog.text = ''; } else if ( flashPashObject == clientLog_fp ) { btnSaveClientLog.setLabel( 'Saving log...' ); } else if ( flashPashObject == serverLog_fp ) { btnSaveServerLog.setLabel( 'Saving log...' ); } with ( flashPashObject ) { setInterval( options.txtInterval.text ); setMaxWaitTime( options.txtMaxWaitTime.text ); var URL = options.txtURL.text + '?dbType=' + escape( cbxDatabaseType.getValue() ); URL += '&dbHost=localhost'; URL += '&dbName=' + escape( cbxDatabaseName.getValue() ); URL += '&dbUser=' + escape( txtUser.text ); URL += '&dbPass=' + escape( txtPass.text ); URL += '&debug=' + options.ckbDebug.getValue(); URL += '&errorReporting=' + escape( options.cbxErrorReporting.getValue() ); setFlashPashURL( URL ); } txtServerLog.text = ''; } function setSQLcondition() { if ( options.txtSQLcondition.length > 0 ) demo_fp.setSQLcondition( options.txtSQLcondition.text ); else demo_fp.setSQLcondition( null ); } function btnHelp_click() { setupTabSheet( help ); } function btnOptions_click() { setupTabSheet( options ); } function btnCurrent_click() { setupTabSheet( current ); } function btnMeta_click() { setupTabSheet( meta ); } function btnGeneric_click() { setupTabSheet( generic ); } function btnStash_click() { setupTabSheet( stash ); } function setupTabSheet( tabSelected ) { /* oh for a tabsheet component! :) */ options._visible = ( tabSelected == options ); meta._visible = ( tabSelected == meta ); current._visible = ( tabSelected == current ); generic._visible = ( tabSelected == generic ); stash._visible = ( tabSelected == stash ); help._visible = ( tabSelected == help ); btnOptions.setEnabled( tabSelected != options ); btnMeta.setEnabled( tabSelected != meta ); btnCurrent.setEnabled( tabSelected != current ); btnGeneric.setEnabled( tabSelected != generic ); btnStash.setEnabled( tabSelected != stash ); btnHelp.setEnabled( tabSelected != help ); /* This isn't quite right, the disabled button should be darker :( */ btnOptions.onRollOut(); btnOptions.gotoFrame( 4 ); btnOptions.drawFrame(); btnMeta.onRollOut(); btnCurrent.onRollOut(); btnGeneric.onRollOut(); btnStash.onRollOut(); btnHelp.onRollOut(); if ( meta._visible ) { with ( meta ) { txtMetaInput._height = 85; sbvMetaInput._height = 85; lblMetaResult._visible = false; txtMetaResult._visible = false; sbhMetaResult._visible = false; } } else if ( generic._visible ) { with ( generic ) { lblSQLresult._visible = false; lblSQLresultBug._visible = false; txtSQLresult._visible = false; sbhSQLresult._visible = false; } } } /*==-==-==-==-==-==-==-==-==-==-==-==-==-==-==+ | TabSheet/MovieClip 'options' functions | +==-==-==-==-==-==-==-==-==-==-==-==-==-==-==*/ function ckbLimitRecordSet_click( component ) { with ( options ) { var recordLimit = ckbLimitRecordSet.getValue(); if ( recordLimit ) { lblRecordLimit.htmltext = 'Record limit for <b>doSelect</b> method'; lblLimitFrom.htmltext = 'Start limiting from record number'; txtRecordLimit._visible = true; txtLimitFrom._visible = true; txtInterval._visible = false; txtMaxWaitTime._visible = false; } else { lblRecordLimit.htmltext = '<b>interval</b> (ms) for <b>onStateChange</b>'; lblLimitFrom.htmltext = '<b>maxWaitTime</b> (ms) before timeout'; txtRecordLimit._visible = false; txtLimitFrom._visible = false; txtInterval._visible = true; txtMaxWaitTime._visible = true; } } } function ckbDebug_click() { demo_fp.setDebug( options.ckbDebug.getValue() ); updateLogLabels(); } function ckbFlashPashEvents_click() { updateLogLabels(); } function ckbFireFlyEvents_click() { updateLogLabels(); } /*==-==-==-==-==-==-==-==-==-==-==-==-==-==-==+ | TabSheet/MovieClip 'meta-data' functions | +==-==-==-==-==-==-==-==-==-==-==-==-==-==-==*/ function cbxMetaDataType_click() { with ( meta ) { txtMetaInput.text = ''; txtMetaInput._height = 85; sbvMetaInput._height = 85; lblMetaResult._visible = false; txtMetaResult._visible = false; sbhMetaResult._visible = false; cbxMetaDataTable._visible = false; var metaType = cbxMetaDataType.getValue(); switch ( metaType ) { case demo_fp.FP_META_TYPE_DATABASES : lblMetaInput._visible = false; txtMetaInput._visible = false; sbvMetaInput._visible = false; ckbSetDataSource._visible = false; ckbCreateNodes._visible = false; btnDoMeta.setLabel( 'Get list of databases' ); break; case demo_fp.FP_META_TYPE_TABLES : lblMetaInput._visible = false; txtMetaInput._visible = false; sbvMetaInput._visible = false; ckbSetDataSource._visible = false; ckbCreateNodes._visible = false; btnDoMeta.setLabel( 'Get tables in ' + cbxDatabaseName.getValue() ); break; case demo_fp.FP_META_TYPE_COLUMNS : txtMetaInput.text = ''; lblMetaInput.text = 'Select table '; lblMetaInput._visible = true; cbxMetaDataTable._visible = true; txtMetaInput._visible = false; sbvMetaInput._visible = false; ckbSetDataSource._visible = false; ckbCreateNodes._visible = false; btnDoMeta.setLabel( 'Get columns from table' ); break; case demo_fp.FP_META_TYPE_SQL : lblMetaInput.text = 'Enter SQL query'; txtMetaInput.text = 'SELECT *' + chr( 10 ) + 'FROM table1'; lblMetaInput._visible = true; txtMetaInput._visible = true; sbvMetaInput._visible = true; ckbSetDataSource._visible = true; ckbCreateNodes._visible = true; btnDoMeta.setLabel( 'Get field meta-data' ); break; } } } function btnDoMeta_click() { with ( meta ) { lblMetaResult._visible = false; txtMetaResult._visible = false; sbhMetaResult._visible = false; var metaType = cbxMetaDataType.getValue(); if ( metaType == demo_fp.FP_META_TYPE_SQL) { firefly_grd.removeAllColumns(); var setDataSource = ckbSetDataSource.getValue(); var createNodes = ckbCreateNodes.getValue(); var SQLtext = txtMetaInput.text; } else if ( metaType == demo_fp.FP_META_TYPE_COLUMNS ) { var SQLtext = cbxMetaDataTable.getValue(); } else if ( metaType == demo_fp.FP_META_TYPE_TABLES ) { var SQLtext = cbxDatabaseName.getValue(); } } setup( demo_fp ); demo_fp.doMeta( metaType, SQLtext, setDataSource, createNodes ); } /*==-==-==-==-==-==-==-==-==-==-==-==-==-==-==+ | TabSheet/MovieClip 'current record' | +==-==-==-==-==-==-==-==-==-==-==-==-==-==-==*/ function btnInsert_click() { setup( demo_fp ); demo_fp.doInsert(); } function btnUpdate_click() { setup( demo_fp ); switch ( firefly_ds.getMode() ) { case FxDataSetClass.InsertMode : return demo_fp.doInsert(); case FxDataSetClass.EditMode : return demo_fp.doUpdate(); default : updateStatus( 'Unable to update server as dataset not in edit or insert mode.' ); return false; } } function btnDelete_click() { setup( demo_fp ); demo_fp.doDelete(); } /*==-==-==-==-==-==-==-==-==-==-==-==-==-==-==+ | TabSheet/MovieClip 'generic' functions | +==-==-==-==-==-==-==-==-==-==-==-==-==-==-==*/ function btnDoSQL_click() { with ( generic ) { lblSQLresult._visible = false; lblSQLresultBug._visible = false; txtSQLresult._visible = false; sbhSQLresult._visible = false; } setup( demo_fp ); demo_fp.doSQL( generic.txtSQLinput.text ); } /*==-==-==-==-==-==-==-==-==-==-==-==-==-==-==+ | TabSheet/MovieClip 'flashPashStash' | +==-==-==-==-==-==-==-==-==-==-==-==-==-==-==*/ function btnStashSelect_click() { //demo_fps.stashSelect( demo_fp ); } function btnStashMeta_click() { //demo_fps.stashMeta( demo_fp, demo_fp.FP_META_TYPE_SQL, true, false ); } function btnTrashStash_click() { //demo_fps.trashStash(); } function btnDumpStash_click() { //demo_fps.dumpStash(); } /*==-==-==-==-==-==-==-==-==-==-==-==-==-==-==+ | TabSheet/MovieClip 'help' functions | +==-==-==-==-==-==-==-==-==-==-==-==-==-==-==*/