Giờ chúng ta sẽ cùng nhau tìm hiểu về Flash trong Bada. Bài viết này, chúng ta sẽ tìm hiểu làm thế nào để đưa một Flash Object vào trong Bada. Vì hạn chế về thời gian cũng như là mục đích của các bài viết tutorial cho Bada mà chúng tôi không chỉ ra làm thế nào để tạo được Flash Object. Giả sử rằng, bạn đã có tập tin .swf rồi, chúng tôi sẽ giới thiệu đến bạn cách nạp nó vào ứng dụng của Bada.

download

Bạn cũng biết, để Bada và Flash Object nói chuyện tốt với nhau thì chúng ta cần trả lời các câu hỏi sau:

  1. Làm sao để đưa Flash Object vào ứng dụng của Bada, hiển thị lên trên Screen được?
  2. Làm thế nào để Bada nhận được thông tin gửi về từ Flash Object hay ngược lại, làm sao để truyền thông tin vào cho Flash Object?
  3. Điều khiển, thực thi được video từ Flash Object thông qua ứng dụng Bada như thế nào?

Bài viết này sẽ giúp bạn trả lời câu hỏi 1: Làm sao để đưa Flash Object vào ứng dụng Bada của bạn.

B1. Bạn tạo một Project mới bằng cách chọn vào File > New > bada Application Project

B2. Bạn nhập tên dự án của bạn, ví du như: FlashAnimation, tiếp đến bạn trả lời các thông tin để hoàn tất việc tạo một project mới.

B3. Tiếp tục, bạn cần nạp tập tin .swf (Flash Object) vào dự án của bạn.

B3.1. Bạn click phải chuột vào Project Explorer > Res, rồi chọn vào item: Import…

B3.2. Một cửa sổ mới sẽ xuất hiện để cho phép bạn chọn đến tập tin .swf của bạn. Bạn chọn vào: General > File System –> chọn Next

B3.3. Tìm đến nới chứa tập tin .swf của bạn rồi thực hiện việc import.

Finish, bạn sẽ nhìn thấy tập tin .swf tại project của bạn như sau:

B4. Giờ đã hoàn tất việc đưa thêm tài nguyên (Flash Object) vào cho ứng dụng của bạn, tiếp đến bạn sẽ sử dụng tài nguyên đó như thế nào. Đơn giản, bạn tạo Form mới rồi đặt Flash Object đó lên. Sau đó là có thể chiêm ngưỡng thành quả của bạn rồi.

B4.1. Bạn thêm mới 2 tập tin FlashAnimationForm.hFlashAnimationForm.cpp theo cấu trúc sau:

B4.2. Bạn thêm các dòng code sau cho 2 tập tin bạn vừa mới tạo ở trên.

FlashAnimationForm.h

/*
 * FlashAnimationForm.h
 *
 *  Created on: May 1, 2010
 *      Author: AWK
 */

#ifndef FLASHANIMATIONFORM_H_
#define FLASHANIMATIONFORM_H_

#include
#include
#include 

class FlashAnimationForm:
	public Osp::Ui::Controls::Form,
	public Osp::Ui::IFlashEventListener
{
public:
		FlashAnimationForm(void);
		bool Initialize(void);
		virtual ~FlashAnimationForm(void);
private:
		Osp::Ui::Controls::Flash *__pFlash;
public:
    virtual result OnInitializing(void);
    virtual void OnFlashDataReceived(const Osp::Ui::Control& source, const Osp::Base::Collection::IList& paramList);
    virtual void OnFlashDataReturned(const Osp::Ui::Control& source, const Osp::Base::Collection::IList& paramList);
    virtual void OnFlashTextEntered(const Osp::Ui::Control& source, Osp::Ui::FlashTextInputMode inputMode, const Osp::Base::String& defaultText, int limitTextLength);
    virtual void OnFlashLayoutChanged(const Osp::Ui::Control& source, Osp::Ui::FlashLayoutStyle layoutStyle);

};

#endif /* FLASHANIMATIONFORM_H_ */

FlashAnimationForm.cpp

/*
 * FlashAnimationForm.cpp
 *
 *  Created on: May 1, 2010
 *      Author: AWK
 */

#include "FlashAnimationForm.h"

using namespace Osp::Base;
using namespace Osp::Graphics;
using namespace Osp::Ui;
using namespace Osp::Ui::Controls;

FlashAnimationForm::FlashAnimationForm(void)
{}

FlashAnimationForm::~FlashAnimationForm(void)
{}

bool
FlashAnimationForm::Initialize(void)
{
	result r = E_SUCCESS;
	r = Form::Construct(FORM_STYLE_NORMAL);
	SetName(L"FlashAnimationForm");

	return true;
}

result
FlashAnimationForm::OnInitializing(void)
{
	result r = E_SUCCESS;
	Rectangle bounds = GetBounds();

	String fileName(L"/Res/animation.swf");

	// Create a Flash
	__pFlash = new Flash();

	// Construct Flash - Animation
	__pFlash->Construct(bounds, FLASH_STYLE_PLAY_WITHOUT_FOCUS, fileName);

	__pFlash->SetQuality(FLASH_QUALITY_HIGH);

	__pFlash->AddFlashEventListener(*this);

	// Add a Flash to the Form
	AddControl(*__pFlash);

	// Must draw a Form before playing
	Draw();
	Show();

	// Play a Flash
	__pFlash->Play();

	return r;
}

// Implement an IFlashEventListener
void
FlashAnimationForm::OnFlashDataReceived(const Osp::Ui::Control& source, const Osp::Base::Collection::IList& paramList)
{
    // Todo:
}
void
FlashAnimationForm::OnFlashDataReturned(const Osp::Ui::Control& source, const Osp::Base::Collection::IList& paramList)
{
    // Todo:
}

void
FlashAnimationForm::OnFlashTextEntered(const Osp::Ui::Control& source, Osp::Ui::FlashTextInputMode inputMode, const Osp::Base::String& defaultText, int limitTextLength)
{
    // Todo:
}

void
FlashAnimationForm::OnFlashLayoutChanged(const Osp::Ui::Control& source, Osp::Ui::FlashLayoutStyle layoutStyle)
{
    // Todo:
}

B4.3. Tiếp đến bạn gọi hiển thị Form tại tập tin FlashAnimation.cpp

bool
FlashAnimation::OnAppInitializing(AppRegistry& appRegistry)
{
	// TODO:
	// Initialize UI resources and application specific data.
	// The application's permanent data and context can be obtained from the appRegistry.
	//
	// If this method is successful, return true; otherwise, return false.
	// If this method returns false, the application will be terminated.

	FlashAnimationForm *pFlashAnimationForm = new FlashAnimationForm();
	pFlashAnimationForm->Initialize();
	GetAppFrame()->GetFrame()->AddControl(*pFlashAnimationForm);

	return true;
}

B5. Giờ bạn có thể xem kết quả như thế nào rồi đấy, ví dụ của chúng tôi như sau: