FlashDevelop calling the iOS method

Source: Internet
Author: User

Source: http://blog.csdn.net/zu12jing/article/details/7331397

Flash development tools with FlashDevelop (because FlashDevelop can also open the Flashbuilder project, in turn, do not know)

I. Create a project

Create an iOS project, this online a lot of information I will not write

Key point: To package to iOS devices, the main thing to see is the default Air_ios_readme.txt file description, which is very detailed for packaging iOS project settings

Two. How to use ANE (in the back of the ANE package)

Ane: Includes all the resources required for all cross-platform

Iii. LIB.A file generation (Environment xcode4.2)

1. Start Xcode, under ios-"Frameworkd&library, create a project for Cocoa Touch Static Library.
2. Once created, from the Flex SDK directory you downloaded, locate the Include folder and find the FlashRuntimeExtensions.h added to the project
3, the system can be generated by default. h file Delete, leave a. m file on the line.
4, below is the contents of the. m file

#import "FlashRuntimeExtensions.h"
#import <AudioToolbox/AudioToolbox.h>
#import <UIKit/UIKit.h>


Freobject Showiconbadagenumber (Freobject ctx, void* funcdata, uint32_t argc, Freobject argv[])
{
NSLog (@ "entering in Showiconbadagenumber ()");
Freobject fo;
Frenewobjectfrombool (NO, &AMP;FO);
NSLog (@ "entering in Showiconbadagenumber ()");

int32_t T;
FREGetObjectAsInt32 (Argv[0], &t);

[[UIApplication sharedapplication] setapplicationiconbadgenumber:t];

return argv[0];
}

Freobject Showalertinfo (Freobject ctx, void* funcdata, uint32_t argc, Freobject argv[])
{
NSLog (@ "Entering Showalertinfo ()");

Freobject fo;
Frenewobjectfrombool (NO, &AMP;FO);

int32_t T;
FREGetObjectAsInt32 (Argv[0], &t);


NSString *tmpstr = [NSString stringwithformat:@ "%d", t];

Uialertview *tmpalert = nil;
Tmpalert = [[Uialertview alloc] initwithtitle:@ "System Information" Message:tmpstr Delegate:nil cancelbuttontitle:@ "Sure" Otherbuttontitles:nil];
[Tmpalert show];
[Tmpalert release];

NSLog (@ "Exiting showalertinfo ()");
return argv[0];
}

Freobject Initnativecode (Freobject ctx, void* funcdata, uint32_t argc, Freobject argv[])
{
NSLog (@ "Entering Initnativecode ()");

NSString *tmpstr = [NSString stringwithformat:@ "%d", 10000];

Uialertview *tmpalert = nil;
Tmpalert = [[Uialertview alloc] initwithtitle:@ "System Information" Message:tmpstr Delegate:nil cancelbuttontitle:@ "Sure" Otherbuttontitles:nil];
[Tmpalert show];
[Tmpalert release];
Nothing to do.

NSLog (@ "Exiting Initnativecode ()");

return NULL;
}


void Contextinitializer (void* extdata, const uint8_t* ctxtype, Freobject ctx, uint32_t* numfunctionstotest, const FREName dfunction** Functionstoset)
{
NSLog (@ "Entering Contextinitializer");
*numfunctionstotest = 3;
Frenamedfunction *func = (frenamedfunction *) malloc (sizeof (frenamedfunction) * 3);

Func[0].name = (const uint8_t*) "Initnativecode";
Func[0].functiondata = NULL;
Func[0].function = &InitNativeCode;

Func[1].name = (const uint8_t*) "Showiconbadagenumber";
Func[1].functiondata = NULL;
Func[1].function = &ShowIconBadageNumber;

Func[2].name = (const uint8_t*) "Showalertinfo";
Func[2].functiondata = NULL;
Func[2].function = &ShowAlertInfo;

*functionstoset = func;
NSLog (@ "exiting Contextinitializer");
}
void Contextfinalizer (Freobject ctx)
{
NSLog (@ "Entering Contextfinalizer ()");

Nothing to clean up.

NSLog (@ "Exiting Contextfinalizer ()");
}


void Extinitializer (void** extdatatoset, frecontextinitializer* Ctxinitializertoset, frecontextfinalizer* Ctxfinalizertoset)
{
NSLog (@ "Entering Extinitializer ()");

*extdatatoset = NULL;
*ctxinitializertoset = &ContextInitializer;
*ctxfinalizertoset = &ContextFinalizer;

NSLog (@ "Exiting Extinitializer ()");

}
void Extfinalizer (void *extdata)
{
NSLog (@ "Entering Extfinalizer ()");

Nothing to clean up.

NSLog (@ "Exiting Extfinalizer ()");
Return
}

The first two functions are written by their own excuses, the following is a general excuse, in the red flag function remember to open up the number of interfaces you write, I was missing a call interface function failed, in the project settings remember to set the enable linking with shared libraried to No , we can now produce. a file.

Four. Production. SWC interface file (Flash builder4.6)

Create a Flex library project, click on Project Properties, Flex Library Build path-resource, select src OK, SWC is produced, here is the code (note: sometimes due to flex version issues to add compiler parameters in the Flex Library compiler tab you add-swf-version 13)

Package Com.coolexp
{
Import Flash.external.ExtensionContext;

public class Aneflex
{
private static var extcontext:extensioncontext = null;

Public Function Aneflex ()
{
Showbadagenum (100);
}

public static function Showbadagenum (num:int): int
{
if (!extcontext)
{
Initextension ();
}

return int (Extcontext.call ("Showiconbadagenumber", num));
}


public static function Showalertinfo (num:int): int
{
if (!extcontext)
{
Initextension ();
}

return int (Extcontext.call ("Showalertinfo", num));
}

public static function Initextension (): void
{
Trace ("Vibration constructor:create an extension context");
Extcontext = Extensioncontext.createextensioncontext ("Com.coolexp.aneFlex", "" ");
Extcontext.call ("Initnativecode");

Extcontext.call ("Showalertinfo", 20);
}

}
}

V. Packaging. ane file

Copy the generated. A and. swc files to the same directory, and copy a. swc file to the. zip extract to copy the two files in the. A file into the same folder (that is, there are currently four files in this directory. A,.swc,.swf,.xml), Create a Extension.xml file (the content is as follows), Com.coolexp.aneFlex this ID is the same as the Flex Library project ID, LIBANEDEMO.A is the name of the. A file that you generated. Then find your Flex library in the ADT file location execute the blue command below to package it into

<extension xmlns= "http://ns.adobe.com/air/extensin/2.7" >
<id>com.coolexp.aneflex</id>
<versionNumber>1</versionNumber>
<platforms>
<platform name= "Iphone-arm" >
<applicationDeployment>
<nativeLibrary>libanedemo.a</nativelibrary>
<initializer>ExtInitializer</initializer>
<finalizer>ExtFinalizer</finalizer>
</applicationDeployment>
</platform>
</platforms>
</extension>

Package. Ane command

"D:\flex Sdk\4.6.0\bin\adt"-package-target ane anedemo.ane EXTENSION.XML-SWC aneflex.swc-platform IPhone-ARM Library. SWF LIBANEDEMO.A

This will result in a Anedemo.ane file under the folder.

Six, call. Ane (FlashDevelop project)

Copy the ane file to the Lib directory, add it to the library, and set it to the external application library. Add-extdir lib/to Packager.bat

Example: Call Adt-package-target%type%%target%%options%%signing_options% "%output%" "%app_xml%"%FILE_OR_DIR%-extdir lib/

Because it is the Extdir Lib directory, put the. ane file under the Lib folder

Add Com.coolexp.aneFlex ID to the Extensions tab in the AS3 Project properties settings

This can be called in your AS3 project. Ane Library, realized only after the discovery can not be compiled online, direct production. IPA packaging successfully runs on ipad

Note: You can use. Ane if you want to build an. apk or. IPA package, otherwise embedding ane in the emulator will not recognize the ID that is configured in the ANE, and the compilation will error

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.