[flexcoders] C Native Extension: Need to replace time structure into millisecond output

2011-12-27 Thread yanlilei64
I'm taking time to experiment how I can track the MIDI timing in milliseconds. 
In this code below contain date and time format and wish to replace with time 
function that is capable of milliseconds precision without huge jump in 
accuracy. This will be run on Window 7 using GCC or MingGW compilers.
Any advice is appreciate!


#include "FlashRuntimeExtensions.h"
#include "Stdlib.h"
#include "SampleANE.h"
#include "String.h"
#include "time.h"

//If AIR can access this function, return 1, ANE is avail
FREObject isSupported(FREContext ctx, void* funcData, uint32_t argc, FREObject 
argv[]) {
FREObject result;

uint32_t isSupportedInThisOS = 1;
FRENewObjectFromBool(isSupportedInThisOS, &result); 
//Boolean to object and return, FRE_OK

return result;
}

FREObject getTestString(FREContext ctx, void* funcData, uint32_t argc, 
FREObject argv[]) {
FREObject result = 0;

//Temporary values to hold our actionscript code.
uint32_t len = -1;
const uint8_t *str = 0;
char *temp;
uint8_t *strAll;

time_t curtime;
struct tm *loctime;

curtime = time(NULL);

loctime = malloc(sizeof(curtime));

loctime = localtime(&curtime);

char *asc = asctime(loctime);

//Turn our actionscrpt code into native code.
if(FREGetObjectAsUTF8(argv[0], &len, &str) == FRE_OK) {
temp = "Hello World! This is ";

strAll = (char *)malloc(strlen(temp) + strlen(str) + 
strlen(asc) + 1);
strcpy(strAll,temp);
strcat(strAll,str);
strcat(strAll,asctime(loctime));
}

FRENewObjectFromUTF8(strlen((const char *)strAll)+1, (const uint8_t 
*)strAll, &result); //UTF8 to object and return
free(strAll);
free(temp);

return result;
}

FREObject getHelloWorld(FREContext ctx, void* funcData, uint32_t argc, 
FREObject argv[]) {
FREObject result;

const char *str = "Hello World! This is a String";
FRENewObjectFromUTF8(strlen(str)+1, (const uint8_t *)str, &result);

return result;
}


void contextInitializer(void* extData, const uint8_t* ctxType, FREContext ctx, 
uint32_t* numFunctions, const FRENamedFunction** functions)
{
// setup the number of functions in this extension
*numFunctions = 3;

// create an array to store all the functions we will use.
FRENamedFunction* func = (FRENamedFunction*) 
malloc(sizeof(FRENamedFunction) * (*numFunctions));

 // create an array entry for each function
func[0].name = (const uint8_t*) "getTestString";
func[0].functionData = NULL;//data type from ctxType?
func[0].function =  &getTestString;

func[1].name = (const uint8_t*) "isSupported";
func[1].functionData = NULL;//data type from ctxType?
func[1].function =  &isSupported;

func[2].name = (const uint8_t*) "getHelloWorld";
func[2].functionData = NULL;//data type from ctxType?
func[2].function =  &getHelloWorld;

// create an array to store all the functions we will use.
*functions = func;
}

// A native context instance is disposed
void contextFinalizer(FREContext ctx) {
return;
}

void initializer(void** extData, FREContextInitializer* ctxInitializer, 
FREContextFinalizer* ctxFinalizer) {
*ctxInitializer = &contextInitializer;
*ctxFinalizer = &contextFinalizer;
}

void finalizer(void* extData) {
return;
}




[flexcoders] Re: Bug in C function caused AIR to crash

2011-12-26 Thread yanlilei64
No one know?


--- In flexcoders@yahoogroups.com, "yanlilei64"  wrote:
>
> I want to pass the "James" string to getTestString function, the first
> time, the string could return "This is James" without any error.
> Subsequently after the button is click, the application will just
> hang/crash (grey out), it seem there some bugs in this code?
> 
> Screenshot: http://imagetwist.com/7896zupwtu97/a.jpg.html
> 
> Code:
> 
> FREObject getTestString(FREContext ctx, void* funcData, uint32_t argc,
> FREObject argv[]) {
>FREObject result;
> 
>//Temporary values to hold our actionscript code.
>uint32_t albumLength;
>const uint8_t *str;
>uint8_t *strAll;
> 
>//Turn our actionscrpt code into native code.
>FREGetObjectAsUTF8(argv[0], &albumLength, &str);
>strcpy(strAll,"This is ");
>strcat(strAll,str);  //str is "James"
> 
>//const char *str = "this is ";
>FRENewObjectFromUTF8(strlen(strAll)+1, (uint8_t *)strAll,
> &result); //UTF8 to object and return
> 
>return result;
> }
>




[flexcoders] Bug in C function caused AIR to crash

2011-12-25 Thread yanlilei64
I want to pass the "James" string to getTestString function, the first
time, the string could return "This is James" without any error.
Subsequently after the button is click, the application will just
hang/crash (grey out), it seem there some bugs in this code?

Screenshot: http://imagetwist.com/7896zupwtu97/a.jpg.html

Code:

FREObject getTestString(FREContext ctx, void* funcData, uint32_t argc,
FREObject argv[]) {
   FREObject result;

   //Temporary values to hold our actionscript code.
   uint32_t albumLength;
   const uint8_t *str;
   uint8_t *strAll;

   //Turn our actionscrpt code into native code.
   FREGetObjectAsUTF8(argv[0], &albumLength, &str);
   strcpy(strAll,"This is ");
   strcat(strAll,str);  //str is "James"

   //const char *str = "this is ";
   FRENewObjectFromUTF8(strlen(strAll)+1, (uint8_t *)strAll,
&result); //UTF8 to object and return

   return result;
}



[flexcoders] Join Flex Connections in Facebook!

2011-12-12 Thread yanlilei64
Focus for Flash and Flex developers to reach out each others and building 
community connections in the social networking. Let join and spread the words 
with your friends.

https://www.facebook.com/pages/Flex-Connections/190251661059191



[flexcoders] Move borderContainer, High CPU processing

2011-09-05 Thread yanlilei64
Tried to optimize AIR application 2.7 except when it come to move 
borderContainer from point A to point B, it would use high CPU processing. Any 
trick to reduce CPU processing or minimize rendering update?

other than "libspark" library which offer efficient motion to any objects, is 
there any tween library that can move borderContainer as fluid as possible?