Translate

Home > April 2011

April 2011

How to get the button id on click event

Saturday, April 30, 2011 Category : , 0

private function clickEvent(clickEvent:Event):void
{
var buttonName:String = clickEvent.currentTarget.id;
}
In the button call the function(clickEvent(event)) on click event

Error creating AIR file: error 306: descriptor support one of the following profiles: desktop mobileDevice, extendedMobileDevice, tv

Tuesday, April 26, 2011 Category : 0

This error arises when I used NativeProcess which is available only on extendedDesktop profile.

SOLUTION

Add the desktop profile after the extendedDesktop making it:


<supportedProfiles>extendedDesktop desktop</supportedProfiles>

Flash Button Click Event Handler

Category : 0

btn_close.addEventListener(MouseEvent.CLICK, btn_closeClick);

 function btn_closeClick(event: MouseEvent) {
   
    parent.removeChild(this);
    this.Sharakuplayer.stop();
}

Load Movie Clip at runtime

Category : 0

go to your movie clip and set following properties

 
var myMovieClip:MovieClip = new MPlayer();
    addChild(myMovieClip);
    myMovieClip.x = 10;
    myMovieClip.y =30;
    myMovieClip.Sharakuplayer.source = videoFileName;
    myMovieClip.addEventListener(MouseEvent.MOUSE_DOWN, mouseDownDragger);
    myMovieClip.addEventListener(MouseEvent.MOUSE_UP, mouseUpDragger);
}
function mouseDownDragger(e:MouseEvent):void
{
e.currentTarget.startDrag();
}
function mouseUpDragger(e:MouseEvent):void
{
e.currentTarget.stopDrag();
}

Installing the Adobe AIR 2 SDK in Eclipse

Saturday, April 23, 2011 Category : 0

1. Download and Install the Air 2 Runtime and Air 2 SDK
The first step is to download the Air 2 runtime which installs itself within the operating system. The second step is to download the Air 2 SDK, which downloads as a zip file. Assuming you have Flex 2, 3, or 4 installed, there should be a plugin sdks directory that contains an AIR runtime folder such as:

  1. Go to 'C:\Program Files\Adobe\Adobe Flash Builder 4\sdks'
  2. Create a new folder '3.5.0 + AIR SDK'
  3. Copy over content of '3.5.0' to '3.5.0 + AIR SDK'
  4. Copy over content of downloaded AIR SDK to '3.5.0 + AIR SDK'
  5. In Flash Builder, go into Project > Properties > Flex Compiler
  6. Select 'Configure Flex SDKs'
  7. Click 'Add', browse to '3.5.0 + AIR SDK' created above, and call it 'Flex 3.5.0 + AIR SDK' and check it.
  8. Select 'Flex 3.5.0 + AIR SDK' for 'Use a specific SDK'
In short, the app-descriptor for my application (such myApplication.xml) requires that the namespace reference xmlns be changed from

http://ns.adobe.com/air/application/1.5
to http://ns.adobe.com/air/application/2.6

Once you change the version number, the application will compile and run without issue.

if not in your app.xml file add following line in your application tag

<supportedProfiles>extendedDesktop</supportedProfiles>

Open an External Exe File from Flex Builder 3

Category : , 0

        import flash.desktop.NativeProcess;
        import flash.desktop.NativeProcessStartupInfo;

private function btn_flipbook_click(event:Event):void {

                    if(NativeProcess.isSupported)
                    {
                            var ProcessStartupInfo:NativeProcessStartupInfo = new NativeProcessStartupInfo();
                            var _FileName:String = "";
                            _FileName = File.applicationDirectory.nativePath + "\\book.exe";
                            var mp:File = new File();
                            mp = mp.resolvePath(_FileName);
                            ProcessStartupInfo.executable = mp;
                            var process:NativeProcess = new NativeProcess();
                            process.start(ProcessStartupInfo);
                    }


    }

if you find any problem to get NativeProcess then you shoud need to update your Air SDK for Flex your Builder  , See this Link : http://littleprograming.blogspot.com/2011/04/installing-adobe-air-2-sdk-in-eclipse.html

Xcode SQLLITE INSERT and SELECT

Tuesday, April 19, 2011 Category : 4

1. Create SQL Light DataBase By Following command in your MAC Terminal

o firstly we want to create a sqlite database file. Open up the Terminal and get into your project directory. Now type:
 sqlite3 names.db
This will create the file ‘names.db’ at the path your at in the Terminal. Now to check the database contents and close, type:
1> .tables
2> .quit

 create table allusers(user_id DECIMAL,user_name varchar(50));



2. Create a new objective-c class file with named "dbController" 


 in header file add following code 
--------------------------------------
#define DATABASE_NAME @"TweetUser.db"
#define DATABASE_TITLE @"Tweet User"


@interface dbController : NSObject {
NSMutableArray *_scoresArray ;
NSMutableArray *UserArray;
}

- (NSString *) getWritableDBPath;
-(void)createEditableCopyOfDatabaseIfNeeded;
-(void)saveUserInDatabase:(NSString *)user_id:(NSString *)user_name;
-(void)loadUserFromDatabase;
-(NSMutableString *)LoadData;
- (NSMutableArray *)FindUserFromDatabase:(NSString *)user_id;
@end

3. in implementaion file add following code



#import "dbController.h"
#import <sqlite3.h>

@implementation dbController


- (NSString *) getWritableDBPath {

    NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory , NSUserDomainMask, YES);
    NSString *documentsDir = [paths objectAtIndex:0];
    return [documentsDir stringByAppendingPathComponent:DATABASE_NAME];

}


static int loadTimesCallback(void *context, int count, char **values, char **columns)
{
    NSMutableArray *times = (NSMutableArray *)context;
    for (int i=0; i < count; i++) {
        const char *nameCString = values[i];
        [times addObject:[NSString stringWithUTF8String:nameCString]];
    }
    return SQLITE_OK;
}

- (void)loadUserFromDatabase
{
    NSString *file = [self getWritableDBPath];
NSFileManager *fileManager = [NSFileManager defaultManager];
BOOL success = [fileManager fileExistsAtPath:file]; 
// If its not a local copy set it to the bundle copy
if(!success) {
//file = [[NSBundle mainBundle] pathForResource:DATABASE_TITLE ofType:@"db"];
[self createEditableCopyOfDatabaseIfNeeded];
}
_scoresArray = [[NSMutableArray alloc] init];
    sqlite3 *database = NULL;
    if (sqlite3_open([file UTF8String], &database) == SQLITE_OK) {
        sqlite3_exec(database, "select * from allusers", loadTimesCallback, _scoresArray, NULL);
    }
    sqlite3_close(database);
}


- (NSMutableArray *)FindUserFromDatabase:(NSString *)user_id
{
    NSString *file = [self getWritableDBPath];
NSFileManager *fileManager = [NSFileManager defaultManager];
BOOL success = [fileManager fileExistsAtPath:file]; 
// If its not a local copy set it to the bundle copy
if(!success) {
//file = [[NSBundle mainBundle] pathForResource:DATABASE_TITLE ofType:@"db"];
[self createEditableCopyOfDatabaseIfNeeded];
}
//[UserArray removeObjectsInArray:UserArray];
UserArray = [[NSMutableArray alloc] init];
    sqlite3 *database = NULL;
    if (sqlite3_open([file UTF8String], &database) == SQLITE_OK) {
NSString *SQLSTMNT =  [NSString stringWithFormat:@"select * from allusers where user_id =%@",user_id];
const char *sql = [SQLSTMNT UTF8String];
        sqlite3_exec(database, sql, loadTimesCallback, UserArray, NULL);

    }
    sqlite3_close(database);
[UserArray release];
return UserArray;
}

-(NSMutableString *)LoadData {
// Update text
NSMutableString *content = [[NSMutableString alloc] init];
for (int i = 0; i < [_scoresArray count]; i++) {
NSString *data = [_scoresArray objectAtIndex:i];
if(((i+2)%2)==0) {
[content appendString:[NSString stringWithFormat:@"ID: %@",data]];
} else if(((i+1)%2)==0) {
NSLog(@"%d",((i+2) %2));
[content appendString:[NSString stringWithFormat:@"Name: %@",data]];
[content appendString:@"\n"];
}
}
[content release];
return content;
}


-(void)saveUserInDatabase:(NSString *)user_id:(NSString *)user_name {
// Copy the database if needed
[self createEditableCopyOfDatabaseIfNeeded];
NSString *filePath = [self getWritableDBPath];
sqlite3 *database;
if(sqlite3_open([filePath UTF8String], &database) == SQLITE_OK) {
//NSString *temp = [NSString stringWithFormat:@"insert into allusers (user_id,user_name) VALUES (%@,%@)",user_id,user_name];
const char *sqlStatement = "insert into allusers (user_id,user_name) VALUES (?,?)";
sqlite3_stmt *compiledStatement;
if(sqlite3_prepare_v2(database, sqlStatement, -1, &compiledStatement, NULL) == SQLITE_OK)    {
sqlite3_bind_text( compiledStatement, 1,[user_id UTF8String], -1, SQLITE_TRANSIENT);
sqlite3_bind_text( compiledStatement, 2,[user_name UTF8String], -1, SQLITE_TRANSIENT);
}
if(sqlite3_step(compiledStatement) != SQLITE_DONE ) {
NSLog( @"Save Error: %s", sqlite3_errmsg(database) );
}
sqlite3_finalize(compiledStatement);
}
sqlite3_close(database);
}

-(void)createEditableCopyOfDatabaseIfNeeded 
{
    // Testing for existence
    BOOL success;
    NSFileManager *fileManager = [NSFileManager defaultManager];
    NSError *error;
    NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,
NSUserDomainMask, YES);
    NSString *documentsDirectory = [paths objectAtIndex:0];
    NSString *writableDBPath = [documentsDirectory stringByAppendingPathComponent:DATABASE_NAME];
    success = [fileManager fileExistsAtPath:writableDBPath];
    if (success)
        return;
    // The writable database does not exist, so copy the default to
    // the appropriate location.
    NSString *defaultDBPath = [[[NSBundle mainBundle] resourcePath]
  stringByAppendingPathComponent:DATABASE_NAME];
    success = [fileManager copyItemAtPath:defaultDBPath
  toPath:writableDBPath
error:&error];
    if(!success)
    {
        NSAssert1(0,@"Failed to create writable database file with Message : '%@'.",
  [error localizedDescription]);
    }
}


@end
================================

4. Now in your class which is load by a xib file use following code


-(IBAction)btnAdd:(id)sender {
if(textfield.text != @"" && textID.text != @"") {

NSMutableArray *dataArr = [userDB FindUserFromDatabase:textID.text];
if([dataArr count]==0) {
// Insert into the database
[userDB saveUserInDatabase:textID.text:textfield.text];
[userDB loadUserFromDatabase];
// Update the table view contents
textView.text =[userDB LoadData];
}
[textfield resignFirstResponder];
[textID resignFirstResponder];
}
}

- (void)viewDidLoad {
    [super viewDidLoad];
userDB = [[dbController alloc]init];
[userDB loadUserFromDatabase];
// Update the table view
textView.text = [userDB LoadData];
}

5. Run XOCDE 
6. Source File 

Powered by Blogger.