Skip to content

Instantly share code, notes, and snippets.

View s9tpepper's full-sized avatar

Omar Gonzalez s9tpepper

View GitHub Profile
The SkinnableItemRenderer is used exactly like s:ItemRenderer. The difference being SkinnableItemRenderer
allows you to use SkinPart metadata in your ItemRenderer definition. As a result of being able to skin the
item renderer, the autoDrawBackground capabilities are lost as the super class is no longer Group/GroupBase.
This is the only lost functionality in SkinnableItemRenderer. The example Flex project is in the repository,
which includes the examples below.
Example Application:
<?xml version="1.0" encoding="utf-8"?>
<s:WindowedApplication xmlns:fx="http://ns.adobe.com/mxml/2009"
This example shows how you would set the scroll position of a scrollable
component to the max scroll position in Flex 3 and how it is handled in Flex 4.
// Flex 4
// myView = Some view class.
// myScroller = s:Scroller
// myContentContainer = s:Group
var maxScrollPosition:Number = myView.myContentContainer.height - myView.myScroller.viewport.height;
myView.myScroller.viewport.verticalScrollPosition = maxScrollPosition;
@s9tpepper
s9tpepper / creatingAMongoObject.as
Created July 9, 2011 22:57
Creating a Mongo object
/* Creating a Mongo object requires you have the
domain to your mongodb server and the port number,
the default is 27017.*/
var mongo:Mongo = new Mongo("your.mongo.com", 27017);
@s9tpepper
s9tpepper / navigating.as
Created July 9, 2011 23:16
Navigating through databases and collections
/* Accessing a database is done using the db() method */
mongo.db("myDatabase")
/* A reference can be stored to the DB object. */
var myDatabase:DB = mongo.db("myDatabase");
/* Accessing a collection is using the collection() method,
@s9tpepper
s9tpepper / connecting.as
Created July 9, 2011 23:34
Connecting to mongodb
/* Add a handler to the connected Signal object to hook
in to when the database has established a connection */
mongo.db("myDatabase").connected.add(_onDBConnected);
/* Call connect() to try a connection with mongodb */
mongo.db("myDatabase").connect();
/* The Signal handler must accept a DB object, it is
a referece to the mongo.db("myDatabase") object. */
function onDBConnected(db:DB):void
@s9tpepper
s9tpepper / authenticating.as
Created July 10, 2011 00:01
Authenticating with a database
function onDBConnected(db:DB):void
{
/* First create a Credentials object using your username/password */
var dbCredentials:Credentials = new Credentials("db_user_name", "db_user_password");
/* Add callback handlers for authentication problems and authenticated
Signals objects */
mongo.db("myDatabase").authenticationProblem.add(onAuthenticationProblem);
mongo.db("myDatabase").authenticated.add(onDBAuthenticated);
@s9tpepper
s9tpepper / document.as
Created July 10, 2011 00:10
Document object
/* The Document object is used to represent BSON documents
and queries to perform mongodb operations. An empty BSON
document is just a blank Document instance */
var document:Document = new Document();
/* Documents whose properties are all String and number
type values can be created inline using the Document
constructor, {"hello":"world", "type":"message"} is
written inline as below */
@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.
@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 / 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);