Skip to content
This repository has been archived by the owner on May 17, 2022. It is now read-only.

B.2 Init Realtime DB

Hadi Tavakoli edited this page Jul 20, 2017 · 3 revisions

Initialize Firebase Realtime Database

You can initialize the realtime database by calling DB.init(); As soon as you initialized the firebaseDatabase.ane in your project, you will be ready to read and write data to your Firebase database.

NOTE: Make sure you have already initialized the Firebase core before trying any other Firebase child ANEs.

Write to your database

initialize an instance of your database and reference the location you want to write to.

import com.myflashlab.air.extensions.firebase.db.*;

// Write a message to the database
DB.init();
var myRef:DBReference = DB.getReference("message");
myRef.setValue("Hello, World!");

You can save a range of data types to the database this way, including ActionScript Arrays or Objects. When you save an object the responses from any getters will be saved as children of this location.

Read from your database

To make your app data update in realtime, you should add a DBEvents.VALUE_CHANGED listener to the reference you just created.

This event is triggered once when the listener is attached and again every time the data changes, including the children.

// Read from the database
myRef.addEventListener(DBEvents.VALUE_CHANGED, onDataChange);
myRef.addEventListener(DBEvents.VALUE_CHANGE_FAILED, onCancelled);

function onDataChange(e:DBEvents):void
{
	// This method is called once with the initial value and again
	// whenever data at this location is updated.
	if (e.dataSnapshot.exists)
	{
		if (e.dataSnapshot.value is String) 		trace("onValueChanged String value = " + e.dataSnapshot.value);
		else if (e.dataSnapshot.value is Number) 	trace("onValueChanged Number value = " + e.dataSnapshot.value);
		else if (e.dataSnapshot.value is Boolean) 	trace("onValueChanged Boolean value = " + e.dataSnapshot.value);
		else if (e.dataSnapshot.value is Array) 	trace("onValueChanged Array value = " + JSON.stringify(e.dataSnapshot.value));
		else 										trace("onValueChanged Object value = " + JSON.stringify(e.dataSnapshot.value));
	}
}

function onCancelled(e:DBEvents):void
{
	trace("Failed to read value: " + e.msg);
}

Prepare for Launch

Before launching your app, we recommend walking through our launch checklist to make sure your app is ready to go!

Introduction to Firebase ANEs collection for Adobe Air apps


Get Started with Firebase Core in AIR

  1. Prerequisites
  2. Add Firebase to your app
  3. Add the Firebase SDK
  4. Init Firebase Core
  5. Available ANEs
  6. Managing Firebase iid

Get Started with Analytics

  1. Add Analytics ANE
  2. Init Analytics ANE
  3. Log Events
  4. Set User Properties

Get Started with Crashlytics

  1. Add Crashlytics ANE
  2. Test Your Implementation
  3. Customize Crash Reports
  4. Upload .dSYM for iOS apps

Get Started with DynamicLinks

  1. Add DynamicLinks ANE
  2. Init DynamicLinks ANE
  3. Create DynamicLinks
  4. Receive DynamicLinks
  5. View Analytics

Get Started with Authentication

  1. Add Authentication
  2. Init Authentication
  3. Manage Users
  4. Phone Number
  5. Custom Auth
  6. Anonymous Auth
  7. State in Email Actions
  8. Email Link Authentication

Get Started with FCM + OneSignal

  1. Add FCM ANE
  2. Init FCM ANE
  3. Send Your 1st Message
  4. Send Msg to Topics
  5. Understanding FCM Messages
  6. init OneSignal

Get Started with Firestore

  1. Add Firestore
  2. Init Firestore
  3. Add Data
  4. Transactions & Batches
  5. Delete Data
  6. Manage the Console
  7. Get Data
  8. Get Realtime Updates
  9. Simple and Compound
  10. Order and Limit Data
  11. Paginate Data
  12. Manage Indexes
  13. Secure Data
  14. Offline Data
  15. Where to Go From Here

Get Started with Realtime Database

  1. Add Realtime Database
  2. Init Realtime Database
  3. Structure Your Database
  4. Save Data
  5. Retrieve Data
  6. Enable Offline Capabilities

Get Started with Remote Config

  1. Parameters and Conditions
  2. Add Remote Config
  3. Init Remote Config

Get Started with Performance

  1. Add Performance ANE
  2. Init & Start Monitoring

Get Started with Storage

  1. Add Storage ANE
  2. Init Storage ANE
  3. Upload Files to Storage
  4. Download Files to Air
  5. Use File Metadata
  6. Delete Files

Get Started with Functions

  1. Write & Deploy Functions
  2. Add Functions ANE
  3. Init Functions
Clone this wiki locally