//---------------------------------------------------------------------------

#include <vcl.h>
#pragma hdrstop

#include "MainUnit.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma link "FlashPlayerControl"
#pragma resource "*.dfm"
#pragma resource "res\\movie.res"
TMainForm *MainForm;
//---------------------------------------------------------------------------
__fastcall TMainForm::TMainForm(TComponent* Owner)
        : TForm(Owner)
{
}
//---------------------------------------------------------------------------
void __fastcall TMainForm::ButtonSiteClick(TObject *Sender)
{
  ShellExecute(0, NULL, "http://www.f-in-box.com/delphi/", NULL, NULL, SW_SHOW);
}
//---------------------------------------------------------------------------

void __fastcall TMainForm::ButtonOrderClick(TObject *Sender)
{
  ShellExecute(0, NULL, "http://www.f-in-box.com/delphi/order.html", NULL, NULL, SW_SHOW);
}
//---------------------------------------------------------------------------

void __fastcall TMainForm::FormCreate(TObject *Sender)
{
  if (!Flashplayercontrol::IsFlashInstalled())
  {
    ShowMessage("The application needs Flash\nFlash is not installed");
    Application->Terminate();
  }

  TFlashVersion UsingFlashVersion;
  Flashplayercontrol::GetUsingFlashVersion(UsingFlashVersion);

  // Check high version component, i.e. flash version must be at least 7.*.*.*
  if (UsingFlashVersion.version[3] < 7)
  {
    char Message[1024];
    wsprintf(Message, "The Sample needs Flash 7 or higher to play embedded movie\nCurrent version of Flash: %d.%d.%d.%d", UsingFlashVersion.version[3], UsingFlashVersion.version[2], UsingFlashVersion.version[1], UsingFlashVersion.version[0]);
    ShowMessage(Message);
    return;
  }

  TResourceStream* ResourceStream = new TResourceStream(0, "Movie", "SWF");
  FlashPlayerControl1->LoadMovieFromStream(0, ResourceStream);
  delete ResourceStream;

  OpenJPEGDialog->InitialDir = ExtractFileDir(Application->ExeName);
}
//---------------------------------------------------------------------------

void __fastcall TMainForm::FlashPlayerControl1LoadExternalResource(
      TObject *ASender, const WideString URL, TStream *Stream)
{
  if (URL == WideString("images/embedded_image1.jpg"))
  {
    TResourceStream* ResourceStream = new TResourceStream(0, "image1", "IMAGE");
    ResourceStream->SaveToStream(Stream);
    delete ResourceStream;
  }

  if (URL == WideString("images/embedded_image2.jpg"))
  {
    TResourceStream* ResourceStream = new TResourceStream(0, "image2", "IMAGE");
    ResourceStream->SaveToStream(Stream);
    delete ResourceStream;
  }

  if (URL == WideString("images/embedded_image3.jpg"))
  {
    TResourceStream* ResourceStream = new TResourceStream(0, "image3", "IMAGE");
    ResourceStream->SaveToStream(Stream);
    delete ResourceStream;
  }

  if (URL == WideString("images/embedded_image4.jpg"))
  {
    TResourceStream* ResourceStream = new TResourceStream(0, "image4", "IMAGE");
    ResourceStream->SaveToStream(Stream);
    delete ResourceStream;
  }

  if (URL == WideString("images/embedded_image5.jpg"))
  {
    TResourceStream* ResourceStream = new TResourceStream(0, "image5", "IMAGE");
    ResourceStream->SaveToStream(Stream);
    delete ResourceStream;
  }

  if (URL == WideString("images/external_image.jpg"))
    if (OpenJPEGDialog->Execute())
    {
      TMemoryStream* MemoryStream = new TMemoryStream;
      MemoryStream->LoadFromFile(OpenJPEGDialog->FileName);
      MemoryStream->SaveToStream(Stream);
      delete MemoryStream;
    }
}
//---------------------------------------------------------------------------

