Skip to content

Instantly share code, notes, and snippets.

View s9tpepper's full-sized avatar

Omar Gonzalez s9tpepper

View GitHub Profile
@s9tpepper
s9tpepper / gist:1394507
Created November 25, 2011 21:57
modal styles
var css:CSSStyleDeclaration = FlexGlobals.topLevelApplication.styleManager.getStyleDeclaration('global');
css.setStyle('modalTransparency', transparency);
css.setStyle('modalTransparencyColor', color);
css.setStyle('modalTransparencyBlur', blur);
css.setStyle('modalTransparencyDuration', duration);
@s9tpepper
s9tpepper / gist:1094408
Created July 20, 2011 05:36
Getting a Stage reference in FlexUnit test for AS3-only project
// This is in an ActionScript Project in Flash Builder
// Inside FlexUnitApplication.as I added a UI testing environment
// In the builder I pass in a reference to the FlexUnitApplication instance
package
{
import com.project.MyClassTests;
import flash.display.Sprite;
@s9tpepper
s9tpepper / usingTheRemoveMethod.as
Created July 10, 2011 01:24
Using the remove() method
/* Retrieve the _id property from a document returned by mongodb. */
var objectId:ObjectID = documentRetrievedFromMongo._id;
/* Create a selector query using the Document object to specify by _id
which document to remove() */
var selector:Document = new Document();
selector.put("_id", objectId);
/* Call the remove function, there is no return. */
mongo.db("myDatabase").collection("myCollection").remove(selector);
@s9tpepper
s9tpepper / usingTheInsertMethod.as
Created July 10, 2011 01:18
Using the insert() method
/* Use a Document object to build the BSON document to save into the database */
const newDocument:Document = new Document();
newDocument.put("name", "Hello from Flash sucka!");
/* Use the insert() method to save. This method does not return anything */
mongo.db("myDatabase").collection("myCollection").insert(newDocument);
/* Use a getLastError command to get the status of the last insert attempt. */
mongo.db("myDatabase").runCommand(new Document("getLastError:")).addOnce(onLastError);
@s9tpepper
s9tpepper / usingTheCursorGetMoreMethod.as
Created July 10, 2011 01:13
Using the Cursor object getMore() method
/* The getMore() method can be used to load more documents from the database
if getNextDocument() returns null.*/
function onCursorReady(cursor:Cursor):void
{
/*...do stuff...*/
// Before calling getMore() make sure hasMore() returns true.
if (cursor.hasMore())
{
cursor.getMore().add(onGotMore);
@s9tpepper
s9tpepper / usingCursorToArrayMethod.as
Created July 10, 2011 01:07
Using the Cursor object toArray() method
/* Alternatively, once the Cursor is returned to the callback the Cursor's
toArray() method can be used to retrieve an Array of all the documents that
the Cursor object has loaded. */
function onCursorReady(cursor:Cursor):void
{
// Get array of all documents
var documents:Array = cursor.toArray();
// Do something, such as add it to a data provider
@s9tpepper
s9tpepper / usingCursorGetNextDocument.as
Created July 10, 2011 01:01
Using the Cursor object getNextDocument() method
/* Once the Cursor is returned to the callback the Cursor's
getNextDocument() method can be used to handle each of
the documents returned */
function onCursorReady(cursor:Cursor):void
{
// Get the first document
var doc:Object = cursor.getNextDocument();
// If there was a first document, do something and get next.
@s9tpepper
s9tpepper / usingFindMethod.as
Created July 10, 2011 00:55
Using the find() method
/* To specify how many documents to return at a time as well as other find() options
use a FindOptions object. */
const findOptions:FindOptions = new FindOptions();
findOptions.numberToSkip = 0;
findOptions.numberToReturn = 10;
/* Query is handled the same as findOne(), but the handler callback signature
is different for a find() */
const query:Document = new Document("name:Hello from Flash sucka!");
mongo.db("myDatabase").collection("myCollection").find(query, findOptions).add(onCursorReady);
@s9tpepper
s9tpepper / usingFindOneMethod.as
Created July 10, 2011 00:30
Using the findOne() method
/* The findOne() method will take a query and return a single document. The
query is built using the Document class. If no second argument is used in
the find() one method all fields are returned for the document. */
var query:Document = new Document("fieldName:searchValue");
mongo.db("myDatabase").collection("myCollection").findOne(query).addOnce(findOneReply);
/* Returned fields can be limited by using the return fields document. */
var returnFields:Document = new Document("fieldName:1");
var query:Document = new Document("fieldName:searchValue");
@s9tpepper
s9tpepper / usingRunCommandMethod.as
Created July 10, 2011 00:22
Using the runCommand() method
/* All the commands can be executing with the Document object. Simple
commands such as "getLastError" are run as below. The Document requires
a colon in all entries using shorthand, thus "getLastError:" */
mongo.db("myDatabase").runCommand(new Document("getLastError:")).addOnce(onLastError);
function onLastError(opReply:OpReply):void
{
// The command response document will be in the first element
// of the documents Array in the OpReply object. The structure
// of the document will depend on the command executed.