www.pudn.com > C++_Flash.rar > SWFAction.cpp


// SWFAction.cpp: implementation of the CSWFAction class. 
// 
////////////////////////////////////////////////////////////////////// 
 
#include "SWFAction.h" 
 
 
CSWFAction::CSWFAction(bool bButtonAction) 
{ 
	// Init members 
	m_ButtonAction = bButtonAction; 
	m_NumberActions = 0; 
	m_Actions = NULL; 
	m_SWFStream = NULL; 
	m_SWFStreamLength = 0; 
} 
 
CSWFAction::~CSWFAction() 
{ 
	ClearActions(); 
} 
 
void CSWFAction::Stop() 
{ 
	SWF_ACTIONRECORD action; 
	memset(&action, 0, sizeof(SWF_ACTIONRECORD)); 
	action.ActionCode = 0x07; 
 
	// Add new action to the ActionArray 
	m_NumberActions++; 
	if (m_Actions == NULL) 
		m_Actions = (SWF_ACTIONRECORD*)malloc(sizeof(SWF_ACTIONRECORD)); 
	else 
		m_Actions = (SWF_ACTIONRECORD*)realloc(m_Actions, m_NumberActions*sizeof(SWF_ACTIONRECORD)); 
	memcpy(&m_Actions[m_NumberActions-1], &action, sizeof(SWF_ACTIONRECORD)); 
} 
 
void CSWFAction::Play() 
{ 
	SWF_ACTIONRECORD action; 
	memset(&action, 0, sizeof(SWF_ACTIONRECORD)); 
	action.ActionCode = 0x06; 
 
	// Add new action to the ActionArray 
	m_NumberActions++; 
	if (m_Actions == NULL) 
		m_Actions = (SWF_ACTIONRECORD*)malloc(sizeof(SWF_ACTIONRECORD)); 
	else 
		m_Actions = (SWF_ACTIONRECORD*)realloc(m_Actions, m_NumberActions*sizeof(SWF_ACTIONRECORD)); 
	memcpy(&m_Actions[m_NumberActions-1], &action, sizeof(SWF_ACTIONRECORD)); 
} 
 
void CSWFAction::NextFrame() 
{ 
	SWF_ACTIONRECORD action; 
	memset(&action, 0, sizeof(SWF_ACTIONRECORD)); 
	action.ActionCode = 0x04; 
 
	// Add new action to the ActionArray 
	m_NumberActions++; 
	if (m_Actions == NULL) 
		m_Actions = (SWF_ACTIONRECORD*)malloc(sizeof(SWF_ACTIONRECORD)); 
	else 
		m_Actions = (SWF_ACTIONRECORD*)realloc(m_Actions, m_NumberActions*sizeof(SWF_ACTIONRECORD)); 
	memcpy(&m_Actions[m_NumberActions-1], &action, sizeof(SWF_ACTIONRECORD)); 
} 
 
void CSWFAction::PreviousFrame() 
{ 
	SWF_ACTIONRECORD action; 
	memset(&action, 0, sizeof(SWF_ACTIONRECORD)); 
	action.ActionCode = 0x05; 
 
	// Add new action to the ActionArray 
	m_NumberActions++; 
	if (m_Actions == NULL) 
		m_Actions = (SWF_ACTIONRECORD*)malloc(sizeof(SWF_ACTIONRECORD)); 
	else 
		m_Actions = (SWF_ACTIONRECORD*)realloc(m_Actions, m_NumberActions*sizeof(SWF_ACTIONRECORD)); 
	memcpy(&m_Actions[m_NumberActions-1], &action, sizeof(SWF_ACTIONRECORD)); 
} 
 
void CSWFAction::GotoFrame(int frameIndex) 
{ 
	SWF_ACTIONRECORD action; 
	memset(&action, 0, sizeof(SWF_ACTIONRECORD)); 
	action.ActionCode = 0x81; 
	action.Length = 2; 
	action.ACTION_TYPE.ACTION_GOTO_FRAME.FrameIndex = (USHORT)frameIndex; 
 
	// Add new action to the ActionArray 
	m_NumberActions++; 
	if (m_Actions == NULL) 
		m_Actions = (SWF_ACTIONRECORD*)malloc(sizeof(SWF_ACTIONRECORD)); 
	else 
		m_Actions = (SWF_ACTIONRECORD*)realloc(m_Actions, m_NumberActions*sizeof(SWF_ACTIONRECORD)); 
	memcpy(&m_Actions[m_NumberActions-1], &action, sizeof(SWF_ACTIONRECORD)); 
} 
 
void CSWFAction::GotoLabel(UCHAR* frameLabel) 
{ 
	SWF_ACTIONRECORD action; 
	memset(&action, 0, sizeof(SWF_ACTIONRECORD)); 
	action.ActionCode = 0x8C; 
	int frameLabelLength = strlen((char*)frameLabel) + 1; 
	action.Length = frameLabelLength; 
 
	// Add new action to the ActionArray 
	m_NumberActions++; 
	if (m_Actions == NULL) 
		m_Actions = (SWF_ACTIONRECORD*)malloc(sizeof(SWF_ACTIONRECORD)); 
	else 
		m_Actions = (SWF_ACTIONRECORD*)realloc(m_Actions, m_NumberActions*sizeof(SWF_ACTIONRECORD)); 
	memcpy(&m_Actions[m_NumberActions-1], &action, sizeof(SWF_ACTIONRECORD)); 
 
	m_Actions[m_NumberActions-1].ACTION_TYPE.ACTION_GOTO_LABEL.Label = (UCHAR*)malloc(frameLabelLength*sizeof(UCHAR)); 
	memcpy(m_Actions[m_NumberActions-1].ACTION_TYPE.ACTION_GOTO_LABEL.Label, frameLabel, frameLabelLength-1); 
	m_Actions[m_NumberActions-1].ACTION_TYPE.ACTION_GOTO_LABEL.Label[frameLabelLength-1] = '\0'; 
} 
 
void CSWFAction::WaitForFrame(int frameIndex, int skipCount) 
{ 
	SWF_ACTIONRECORD action; 
	memset(&action, 0, sizeof(SWF_ACTIONRECORD)); 
	action.ActionCode = 0x8A; 
	action.Length = 3; 
	action.ACTION_TYPE.ACTION_WAIT_FOR_FRAME.Frame = (USHORT)frameIndex; 
	action.ACTION_TYPE.ACTION_WAIT_FOR_FRAME.SkipCount = (UCHAR)skipCount; 
 
	// Add new action to the ActionArray 
	m_NumberActions++; 
	if (m_Actions == NULL) 
		m_Actions = (SWF_ACTIONRECORD*)malloc(sizeof(SWF_ACTIONRECORD)); 
	else 
		m_Actions = (SWF_ACTIONRECORD*)realloc(m_Actions, m_NumberActions*sizeof(SWF_ACTIONRECORD)); 
	memcpy(&m_Actions[m_NumberActions-1], &action, sizeof(SWF_ACTIONRECORD)); 
} 
 
void CSWFAction::GetURL(UCHAR* urlString, UCHAR* targetString) 
{ 
	SWF_ACTIONRECORD action; 
	memset(&action, 0, sizeof(SWF_ACTIONRECORD)); 
	action.ActionCode = 0x83; 
	int urlLength = strlen((char*)urlString) + 1; 
	int targetLength = strlen((char*)targetString) + 1; 
	action.Length = urlLength + targetLength; 
 
	// Add new action to the ActionArray 
	m_NumberActions++; 
	if (m_Actions == NULL) 
		m_Actions = (SWF_ACTIONRECORD*)malloc(sizeof(SWF_ACTIONRECORD)); 
	else 
		m_Actions = (SWF_ACTIONRECORD*)realloc(m_Actions, m_NumberActions*sizeof(SWF_ACTIONRECORD)); 
	memcpy(&m_Actions[m_NumberActions-1], &action, sizeof(SWF_ACTIONRECORD)); 
 
	m_Actions[m_NumberActions-1].ACTION_TYPE.ACTION_GET_URL.UrlString = (UCHAR*)malloc(urlLength*sizeof(UCHAR)); 
	memcpy(m_Actions[m_NumberActions-1].ACTION_TYPE.ACTION_GET_URL.UrlString, urlString, urlLength-1); 
	m_Actions[m_NumberActions-1].ACTION_TYPE.ACTION_GET_URL.UrlString[urlLength-1] = '\0'; 
 
	m_Actions[m_NumberActions-1].ACTION_TYPE.ACTION_GET_URL.TargetString = (UCHAR*)malloc(targetLength*sizeof(UCHAR)); 
	memcpy(m_Actions[m_NumberActions-1].ACTION_TYPE.ACTION_GET_URL.TargetString, targetString, targetLength-1); 
	m_Actions[m_NumberActions-1].ACTION_TYPE.ACTION_GET_URL.TargetString[targetLength-1] = '\0'; 
} 
 
void CSWFAction::SetTarget(UCHAR* targetString) 
{ 
	SWF_ACTIONRECORD action; 
	memset(&action, 0, sizeof(SWF_ACTIONRECORD)); 
	action.ActionCode = 0x8B; 
	int targetLength = strlen((char*)targetString) + 1; 
	action.Length = targetLength; 
 
	// Add new action to the ActionArray 
	m_NumberActions++; 
	if (m_Actions == NULL) 
		m_Actions = (SWF_ACTIONRECORD*)malloc(sizeof(SWF_ACTIONRECORD)); 
	else 
		m_Actions = (SWF_ACTIONRECORD*)realloc(m_Actions, m_NumberActions*sizeof(SWF_ACTIONRECORD)); 
	memcpy(&m_Actions[m_NumberActions-1], &action, sizeof(SWF_ACTIONRECORD)); 
 
	m_Actions[m_NumberActions-1].ACTION_TYPE.ACTION_SET_TARGET.TargetName = (UCHAR*)malloc(targetLength*sizeof(UCHAR)); 
	memcpy(m_Actions[m_NumberActions-1].ACTION_TYPE.ACTION_SET_TARGET.TargetName, targetString, targetLength-1); 
	m_Actions[m_NumberActions-1].ACTION_TYPE.ACTION_SET_TARGET.TargetName[targetLength-1] = '\0'; 
} 
 
bool CSWFAction::IsButtonAction() 
{ 
	return m_ButtonAction; 
} 
 
void CSWFAction::ClearActions() 
{ 
	if (m_Actions != NULL) 
	{ 
		for (int i=0; i