Skip navigation
Currently Being Moderated

Hello world Native Extension API

Sep 26, 2011 11:05 PM

Hi all :-)

 

I am an android expert and I'd really love to create some cool extensions like the android notifications, but since I don't know much about Flex, I have a lot of trouble getting the test vibrator with native extension working.

(http://www.adobe.com/devnet/air/native-extensions-for-air/extensions/v ibration.html)

 

My sample is still buggy, it is probably beginner's bug, but I don't see how to fix it yet.

 

I am surely not the only native guy trying to do this, so I would like to sumarize here all the steps needed to have our first hello world Native Extension API

 

 

  1. Install Flex 4.5.1 http://www.adobe.com/go/try_flashbuilder/ and download the Adobe AIR 3.0 RC http://labs.adobe.com/downloads/air3.html  as well as the sample files http://download.macromedia.com/pub/developer/air/ane/Vibration.zip
  2. Create a test Flex mobile project.(all the deffault parameters are fine) I'll call it HelloWorldNativeExtension.
  3. (If AIR 3 is not released yet) Do the following to tell Flex builder to use the RC on your test project : http://forums.adobe.com/thread/899921
  4. Unzip the vibration.zip, and go to ready to use extansion.
  5. Go to Project -> Flex buildpath -> Libraries -> Add a new swc. Add the ready to use extension as a library. Then open the extensions properties and change the link type from "bundled with" to "external linkage"
  6. Go to HelloworldNativeExtension-app.xml and in the tag manifestAddition, add : <uses-permission android:name="android.permission.VIBRATE"/>
  7. Write a sample view (as described below)
  8. Run (target platform->android and then chosse to run on a device)
  9. When asked to update the air version, answer yes
  10. Wait a loooong time before it actually start.

 

Here is my code for the sample view:

 

In HelloworldNativeExtension.mxml

Use the following code :

 

<?xml version="1.0" encoding="utf-8"?>

<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009"

               xmlns:s="library://ns.adobe.com/flex/spark"

               xmlns:mx="library://ns.adobe.com/flex/mx">

    <fx:Script>

 

        <![CDATA[

            import com.adobe.nativeExtensions.Vibration;

 

            protected function testButton():void

            {

                textArea.text="Before vibration";

 

                var vibe:Vibration;

                if (Vibration.isSupported)

                {

                    vibe = new Vibration();

                    vibe.vibrate(2000);

                }

 

                textArea.text="After vibration";

 

            }

        ]]>

    </fx:Script>

    <s:Panel title="Exemple MXML" width="330">

        <s:layout>

            <s:VerticalLayout paddingLeft="15" paddingTop="15" paddingBottom="15" paddingRight="15"/>

        </s:layout>

        <s:Label x="223" y="173" text="test" id="textArea"/>

        <s:Button label="Vibrate" click="testButton()"/>

        <s:Label id="result" width="265"/>

    </s:Panel>

</s:Application>

 

 

Well... so far my project doesn't compile because the library is loaded externally. It compiles fine if I add it as a bundled library, but then the virbrator can't work (External native code have to be loaded externally)

And thus so far I get the errors :

DescriptionRessourceChemin Emplacement Type
1046: Ce type est introuvable ou n'est pas une constante de compilation : [flash.display]::IBitmapDrawable.HelloworldNativeExtensionInconnuErreur Flex
1046: Ce type est introuvable ou n'est pas une constante de compilation : [flash.events]::IEventDispatcher.HelloworldNativeExtensionInconnuErreur Flex
1046: Ce type est introuvable ou n'est pas une constante de compilation : [flash.events]::IEventDispatcher.HelloworldNativeExtensionInconnuErreur Flex
1046: Ce type est introuvable ou n'est pas une constante de compilation : [flash.events]::IEventDispatcher.HelloworldNativeExtensionInconnuErreur Flex
1046: Ce type est introuvable ou n'est pas une constante de compilation : [flash.events]::IEventDispatcher.HelloworldNativeExtensionInconnuErreur Flex
1046: Ce type est introuvable ou n'est pas une constante de compilation : [flash.events]::IEventDispatcher.HelloworldNativeExtensionInconnuErreur Flex
1046: Ce type est introuvable ou n'est pas une constante de compilation : [flash.events]::IEventDispatcher.HelloworldNativeExtensionInconnuErreur Flex
1046: Ce type est introuvable ou n'est pas une constante de compilation : [flash.events]::IEventDispatcher.HelloworldNativeExtensionInconnuErreur Flex
1046: Ce type est introuvable ou n'est pas une constante de compilation : [flash.events]::IEventDispatcher.HelloworldNativeExtensionInconnuErreur Flex

 

(Which means something like : 1046: this type cannot be resolved or is not in the buildpath ... So it probably means the project doesn't compile well)

 

 

So I'm still trying to figure out what to do, but I am close I think... Very close.

 
Replies
  • Currently Being Moderated
    Sep 26, 2011 11:12 PM   in reply to Taiko963

    Yes, in fact you are very close

     

    You will have to put an <extensions> tag in app-xml if not already done so:

    <extensions>

    <extensionID>com.adobe.Vibration</extensionID>

    <extensions>

     

    Then since it is FlashBuilder 4.5.1, you will have to package the android application through command line since it requires 1 more parameter -extdir :

    adt -package -target apk . . . app.apk app.xml app.swf -extdir extensions

     

    extensions is the directory which contains your .ane file. Checkout http://www.adobe.com/devnet/air/articles/extending-air.html#articlecon tentAdobe_numberedheader_1 for more details.

     

    Thats all. You should be able to run your app now. Let me know if it still doesnt work.

     

    Thanks,

    Meet

    AIR Team

     
    |
    Mark as:

More Like This

  • Retrieving data ...

Bookmarked By (0)

Answers + Points = Status

  • 10 points awarded for Correct Answers
  • 5 points awarded for Helpful Answers
  • 10,000+ points
  • 1,001-10,000 points
  • 501-1,000 points
  • 5-500 points