Skip to content

Instantly share code, notes, and snippets.

View marchbold's full-sized avatar
🚲
making stuff...

Michael marchbold

🚲
making stuff...
View GitHub Profile
@marchbold
marchbold / distriqt.extension.volume.change.as
Last active August 29, 2015 14:26
Listening to volume change events
if (Volume.isSupported)
{
Volume.service.addEventListener( VolumeEvent.CHANGED, volumeChangedHandler );
Volume.service.register();
}
...
private function volumeChangedHandler( event:VolumeEvent ):void
{
@marchbold
marchbold / distriqt.extension.expansionfiles.setup.as
Last active January 2, 2020 22:39
Setup of the Expansion Files ANE with licensing and salt values
public static const BASE64_PUBLIC_KEY : String = "YOUR_LICENSING_PUBLIC_KEY";
public static const SALT : Vector.<int> = Vector.<int>( [ 1, 43, -12, -1, 54, 98, -100, -12, 43, 2, -8, -4, 9, 5, -106, -108, -33, 45, -1, 84 ]);
...
ExpansionFiles.init( "APP_KEY" );
trace( "ExpansionFiles Supported: " + ExpansionFiles.isSupported );
trace( "ExpansionFiles Version: " + ExpansionFiles.service.version );
@marchbold
marchbold / distriqt.extension.expansionfiles.download.as
Last active September 7, 2015 03:27
Check and download expansion files using the ExpansionFiles ANE
public static const BASE64_PUBLIC_KEY : String = "YOUR_LICENSING_PUBLIC_KEY";
public static const SALT : Vector.<int> = Vector.<int>( [ 1, 43, -12, -1, 54, 98, -100, -12, 43, 2, -8, -4, 9, 5, -106, -108, -33, 45, -1, 84 ]);
...
ExpansionFiles.init( "APP_KEY" );
if (ExpansionFiles.isSupported)
{
ExpansionFiles.service.setup( BASE64_PUBLIC_KEY, SALT );
@marchbold
marchbold / distriqt.extension.expansionfiles.manifestAdditions.xml
Last active September 7, 2015 04:58
Manifest additions for the Expansion Files ANE
<manifest android:installLocation="auto">
<uses-sdk android:minSdkVersion="14" />
<uses-permission android:name="com.android.vending.CHECK_LICENSE" />
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
@marchbold
marchbold / distriqt.extension.ziputils.unzip.as
Created September 17, 2015 03:04
Simple example of unzipping a packaged file 'packaged.zip' to the storage directory 'unzip_dir'
ZipUtils.init( "APP_KEY" );
if (ZipUtils.isSupported)
{
ZipUtils.service.addEventListener( ZipUtilsEvent.UNZIP_COMPLETE, unzip_completeHandler );
ZipUtils.service.addEventListener( ZipUtilsEvent.UNZIP_ERROR, unzip_errorHandler );
ZipUtils.service.unzip(
File.applicationDirectory.resolvePath( "packaged.zip" ).nativePath,
File.applicationStorageDirectory.resolvePath( "unzip_dir" ).nativePath,
@marchbold
marchbold / distriqt.extension.BluetoothLE.stateChange.as
Last active October 19, 2015 07:33
Handle the state changed event from Bluetooth LE
BluetoothLE.service.addEventListener( BluetoothLEEvent.STATE_CHANGED, stateChangedHandler );
switch (BluetoothLE.service.state)
{
case BluetoothLEState.STATE_ON:
// We can use the Bluetooth LE functions
break;
case BluetoothLEState.STATE_OFF:
case BluetoothLEState.STATE_RESETTING:
@marchbold
marchbold / distriqt.extension.bluetoothle.central.scanning.as
Last active June 1, 2016 12:32
Bluetooth LE: Start scanning as a central for advertising peripheral devices
BluetoothLE.service.centralManager.addEventListener( PeripheralEvent.DISCOVERED, central_peripheralDiscoveredHandler );
if (!BluetoothLE.service.centralManager.scanForPeripherals())
{
// There was an error starting to scan, check the state of the adapter!
}
...
private function central_peripheralDiscoveredHandler( event:PeripheralEvent ):void
@marchbold
marchbold / distriqt.extension.bluetoothle.connect.as
Created October 19, 2015 07:51
Bluetooth LE: Connecting to a discovered peripheral
var activePeripheral:Peripheral = null;
BluetoothLE.service.centralManager.addEventListener( PeripheralEvent.DISCOVERED, central_peripheralDiscoveredHandler );
BluetoothLE.service.centralManager.addEventListener( PeripheralEvent.CONNECT, central_peripheralConnectHandler );
BluetoothLE.service.centralManager.addEventListener( PeripheralEvent.CONNECT_FAIL, central_peripheralConnectFailHandler );
BluetoothLE.service.centralManager.addEventListener( PeripheralEvent.DISCONNECT, central_peripheralDisconnectHandler );
BluetoothLE.service.centralManager.scanForPeripherals();
...
@marchbold
marchbold / distriqt.extension.bluetoothle.discoverServices.as
Last active October 19, 2015 08:39
Bluetooth LE: Discover services and characteristics of a connected peripheral
var peripheral:Peripheral = ...; // This snippet assumes you have a connected 'peripheral' object.
var service:Service = null;
peripheral.addEventListener( PeripheralEvent.DISCOVER_SERVICES, peripheral_discoverServicesHandler );
peripheral.addEventListener( PeripheralEvent.DISCOVER_CHARACTERISTICS, peripheral_discoverCharacteristicsHandler );
peripheral.discoverServices();
...
@marchbold
marchbold / distriqt.extension.bluetoothle.readValueForCharacteristic.as
Created October 19, 2015 09:04
Bluetooth LE: Reading the value of a Characteristic
var peripheral:Peripheral = ...; // Previously connected Peripheral
var characteristic:Characteristic = ...; // Discovered Characteristic of interest
peripheral.addEventListener( CharacteristicEvent.UPDATE, peripheral_characteristic_updatedHandler );
peripheral.addEventListener( CharacteristicEvent.UPDATE_ERROR, peripheral_characteristic_errorHandler );
peripheral.readValueForCharacteristic( characteristic );
...