← All extensions

Native extension

KlugTorch

com.klug.torch.Torch

NO APM NEEDED. Download and enjoy. It can’t get any simpler. Just update the Adobe AIR SDK. If you need help, we are here.

Detects whether a device has a camera light and switches it on and off. On iOS this also works while the camera is streaming, without interrupting the stream.

iOSAndroid In production From €9 / year · Buy

Overview

A camera app often needs light: a security camera in a dark room, a scanner, a video call at night. KlugTorch switches the camera light (the LED next to the back camera) on and off while the camera keeps running.

KlugTorch first detects whether the device has a camera light at all. Many tablets and some phones have none, so an app can simply hide its light button there.

It works alongside a live camera stream. KlugTorch does not open a camera of its own, so it never competes with the stream for the camera.

Apps that stream with KlugMedia can also use its built-in torch control. KlugTorch is in daily use in our apps, our proof of concept.

Features

  • Self-contained: one ANE, no core library or dependency ANEs to add
  • Detects whether the device has a camera light
  • Turn the camera light on and off with one call
  • Works while the camera is streaming on iOS, no interruption
  • Reads the current state of the light
  • A change event after every switch, also when it fails
  • One API for iOS and Android

Supported platforms

iOS arm64
Android arm64 · armv7

On devices without a camera light, and on other platforms, isSupported returns false, so the same code can stay in every app.

Getting started

Add the extension to your application descriptor:

app.xml
<extensions>
    <extensionID>com.klug.torch.Torch</extensionID>
</extensions>

The light sits next to the back camera, so the back camera should be the active one.

Code examples

Three complete flows. on() and off() return at once; a change event follows each call, and mode tells you the result. Full documentation →

1 · Show the light button only where there is a light
Setup.as
import com.klug.torch.Torch;
import flash.events.Event;

var torch:Torch = Torch.getInstance();

// iOS: true if the default (back) camera has a torch.
// Android 6+: true if a back-facing camera has a flash.
// False on devices without a light and on other platforms.
lightButton.visible = torch.isSupported;   // lightButton: your app's toggle button
2 · Switch the light and follow the result
Light.as
var wantLight:Boolean = false;

torch.addEventListener( Event.CHANGE, onTorchChange );   // after every on() / off()

function setLight( on:Boolean ):void
{
    wantLight = on;
    if ( on ) torch.on();
    else      torch.off();
}

function onTorchChange( e:Event ):void
{
    // the event carries no detail: read mode for the current state
    lightButton.selected = torch.mode;

    if ( torch.mode != wantLight )   // the light could not be switched
        showMessage( "The light is not available right now." );   // your app
}
On Android the system does not switch the light while another part of the app holds the camera open, for example a stream from AIR's flash.media.Camera. on() then ends with a change event and mode stays false. Apps that stream with KlugMedia use its setTorch() instead.
3 · Switch the light off when the camera stops
Stream.as
function stopStreaming():void
{
    if ( torch.mode ) setLight( false );   // first the light, then the camera
    stopCamera();                          // your app's stream shutdown
    torch.removeEventListener( Event.CHANGE, onTorchChange );
}

API overview

Torch.getInstance()Returns the single instance.
isSupportedTrue only if the device has a usable camera light: on iOS the default (back) camera has a torch, on Android 6+ a back-facing camera has a flash.
on()Turns the camera light on; a change event follows.
off()Turns the camera light off; a change event follows.
modeTrue while the light is on. iOS reads the camera's torch state; Android reports the state of the last successful on() / off().

Events

Event.CHANGE ("change")Dispatched after every on() and off(), also when the light could not be switched. Read mode for the result.

Buy KlugTorch

A yearly licence for one AIR application, with all updates for 12 months. After payment you receive the extension, the ActionScript library and the documentation by e-mail, usually within one business day. Licence and terms

Simple
€9 / year
  • Licence for one AIR application
  • All updates for 12 months
  • No support
Buy Simple
Standard
€39 / year
  • Licence for one AIR application
  • All updates for 12 months
  • Answer by e-mail within 7 days
Buy Standard
Priority
€79 / year
  • Licence for one AIR application
  • All updates for 12 months
  • Answer by e-mail within 48 hours
Buy Priority
Taxes are calculated at checkout by Link (Stripe). You enter the application ID of your AIR app during checkout.

Requirements

AIR SDK51.x (HARMAN)
iOSiOS 17 or later
AndroidAndroid 6.0 (API 23) or later
PermissionsNone of its own
HardwareA camera light next to the back camera