<?xml version="1.0" encoding="UTF-8"?>
<rmml>
<!--
$RCSfile: rnmc_stdFlash.xml $
$Revision: 894 $

last change: $Date: 2009-01-22 19:06:03 +0300 (Чт, 22 янв 2009) $
             $Author: Pavel $

	Lacerta Project
	version 1.0.0.1
	Copyright (C) 2008 RNMC
-->
<composition name="rnmc_stdFlash" class="rnmc_stdMediaObject">
<!--flash name="objectContent" playing="false"/-->
<script><![CDATA[
	this.type = "rnmc_stdFlash"
	this.id = null;
	this.enabled = true;

//	для каждого объекта необходимо определить
//	какие эффекты к нему применимы
	this.fadeEffectEnabled = true;
	this.moveEffectEnabled = true;
	this.scaleEffectEnabled = false;
	
	this.objectFolder = null;
	//this.flashPlaying = FLASH_PLAYING_UNDEFINED;
	//this.objectContent = null;

	this.originalX = 0;
	this.originalY = 0;
	this.originalWidth = 0;
	this.originalHeight = 0;
	this.originalDepth = 0;

	this.objectResult = 0;

	this.playing = OBJECT_PLAYING_UNDEFINED;
// PG: Так как объект Flash, не поддерживает таких событий как RollOver/Out, Press/Release  и т.д.
//		подложим под объект, который будет отвечать за перехват этих событий.
// 	Этот объект будет отлавливать RollOver/Out
	this.interceptObject = null;
// 	Этот объект будет отлавливать Press/Release	
	this.interceptButtonObject = null;

//  массивы действий на Flash события
	this.onFSCommandActions = null;	

	function initFromNode(srcNode){
		var xmlNode = null;
		var xmlAttributeMap = null;
		var xmlAttribute = null;

		xmlAttributeMap = srcNode.attributes;
		if (xmlAttributeMap){
			xmlAttribute = xmlAttributeMap.getNamedItem("id");
			if (xmlAttribute != null && xmlAttribute.specified)
				this.id = xmlAttribute.value;
			xmlAttribute = xmlAttributeMap.getNamedItem("visible");
			if (xmlAttribute != null && xmlAttribute.specified){
				if((xmlAttribute.value).toLowerCase() == "true")
					this.visibility = OBJECT_VISIBILITY_TRUE;
				else if((xmlAttribute.value).toLowerCase() == "false")
					this.visibility = OBJECT_VISIBILITY_FALSE;
			}
			xmlAttribute = xmlAttributeMap.getNamedItem("enabled");
			if (xmlAttribute != null && xmlAttribute.specified && xmlAttribute.value == "false")
				this.disabled = true;
			xmlAttribute = xmlAttributeMap.getNamedItem("playing");
			if (xmlAttribute != null && xmlAttribute.specified){
				if((xmlAttribute.value).toLowerCase() == "true"){
					this.playing = OBJECT_PLAYING_TRUE;
				} else if((xmlAttribute.value).toLowerCase() == "false"){
					this.playing = OBJECT_PLAYING_FALSE;
				}
			}
		}

		if(scene.defaultSettings && scene.defaultSettings.stdFlash){
			this.titleStyle = scene.defaultSettings.stdFlash.titleStyle;
		}		

		xmlNode = srcNode.firstChild;
		while(xmlNode){
			if(xmlNode.nodeName == "rollovermenu"){
				this.parseRolloverMenuNode(xmlNode);
			} else if(xmlNode.nodeName == "param"){
				this.parseParamNode(xmlNode);
			} else if(xmlNode.nodeName == "control"){
				this.parseControlNode(xmlNode);
			} else if(xmlNode.nodeName == "actions"){
			//	стандартые события
				rnmc_stdMediaObject_parseActionsNode(xmlNode);
				this.onFSCommandActions = scene.Utils.parseActionsNode(xmlNode, "onFSCommand");
				this.onEnterZoneActions = scene.Utils.parseActionsNode(xmlNode, "onEnterZone");
				this.onLeaveZoneActions = scene.Utils.parseActionsNode(xmlNode, "onLeaveZone");
				this.onPressZoneActions = scene.Utils.parseActionsNode(xmlNode, "onPressZone");
				this.onReleaseZoneActions = scene.Utils.parseActionsNode(xmlNode, "onReleaseZone");
			} else if(xmlNode.nodeName == "title"){
				this.parseTitleNode(xmlNode);
			} else if(xmlNode.nodeName == "zoom"){
			} else if(xmlNode.nodeName == "hint"){
				this.parseHintNode(xmlNode);
			} else if(xmlNode.nodeName == "effects"){
				this.parseEffectsNode(xmlNode);
			} else if(xmlNode.nodeName == "effect"){	//	старый вариант, NOT SAFE
				this.parseEffectNode(xmlNode);
			} else if(xmlNode.nodeName == "drag"){ //	таскание медиа-объекта
				this.parseDraggingNode(xmlNode);
			} else if(xmlNode.nodeName == "scrollmenu"){ //	
				this.parseScrollMenuNode(xmlNode);
			} else if(xmlNode.nodeName == "objectives"){
				this.parseObjectivesNode(xmlNode);
			}
			xmlNode = xmlNode.nextSibling;
		}
		return true;
	};

	function loadObject(){
		if(!this.objectContent){
			if (!this.interceptObject){
				this.interceptObject = new Composition();
				this.interceptObject.visible = true;
				this.interceptObject.parent = this;
			}
			this.objectContent = new Flash();
			this.objectContent.parent = this.interceptObject;			
			if(this.objectFolder !=  null){
				var src_data = Player.module.extract(this.objectFolder, this.objectFolder);
				this.objectContent.src = src_data + "/" + this.objectSrc;
			} else {
				this.objectContent.src = this.objectSrc;
			}
			if (this.objectHitArea != null)
				this.objectContent.hitArea = this.objectHitArea;
		}
	}

	function unloadObject(){
		this.effectsTarget = null;
		if(this.objectContent){
			this.objectContent.src = null;
			this.objectContent.parent = null;
			this.objectContent = null;
		}
		if (this.interceptObject){
			this.interceptObject.parent = null
			this.interceptObject = null;
		}
	}

	function showObject(){
//trace("rnmc_stdFlash.showObject()");
		this.x = 0;
		this.y = 0;
		this.loadObject();
		if(this.objectContent){
			var objectPosition = this.getPosition();
			this.setPosition(objectPosition[0], objectPosition[1], objectPosition[2], objectPosition[3], this.objectDepth);
			this.objectContent.opacity = this.objectOpacity;
		};

		if(this.onFSCommandActions	||
			this.onEnterZoneActions ||
			this.onLeaveZoneActions ||
			this.onPressZoneActions ||
			this.onReleaseZoneActions){
			this.objectContent.onFSCommand = this.onFSCommandAlias;
		}

	//	перебор присоединённых эффектов для показа
		this.effectsTarget = this.objectContent;
		var showEffectsCount = this.startEffects(EVENT_ON_SHOW);
		if(showEffectsCount == 0){
			this.objectContent.visible = true;
		}
	//	создание объекта подпись
		this.createTitleObject();
	//	если определена панель управления
		if(this.controlDefined && !this.attachedControl){
			this.attachedControl = scene.ControlManager.getControl(this.controlStyle, this);
			if(this.attachedControl){
				this.attachedControl.visible = false;
				this.attachedControl.x = this.controlX;
				this.attachedControl.y = this.controlY;

				this.attachedControl.depth = this.controlDepth;
				this.attachedControl.setDispatcher(this, this.buttonDispatcher);
				if(this.zoomObject){
					this.attachedControl.hideChildControl("zoomout");
					this.attachedControl.showChildControl("zoomin");
				}
				//	кнопки, относящиеся к подписи
				if(this.titleObject){
					if(this.titleVisible){
						this.attachedControl.hideChildControl("showtitle");
						this.attachedControl.showChildControl("hidetitle");
					} else {
						this.attachedControl.hideChildControl("hidetitle");
						this.attachedControl.showChildControl("showtitle");
					}
				} else {
					this.attachedControl.hideChildControl("hidetitle");
					this.attachedControl.hideChildControl("showtitle");
				}
				this.attachedControl.showChildControl("save");
				this.attachedControl.showChildControl("copy");
				this.attachedControl.showObject();
			}
		}
	// если определён хинт
		if(this.hintDefined && this.hintEvent == HINT_EVENT_ONROLLOVER)
			this.objectContent.onRollOver = this.onRollOverHandlerAlias;
		if(this.hintDefined && this.hintEvent == HINT_EVENT_ONPRESS)
			this.objectContent.onRollOver = this.onPressHandlerAlias;

//		this.objectContent.rewind();
        if(this.playing == OBJECT_PLAYING_TRUE)
			this.objectContent.playing = true;
        if(this.playing == OBJECT_PLAYING_FALSE)
			this.objectContent.playing = false;

		rnmc_stdMediaObject_showObject();
		
		if (this.objectSetFocus)
			setFocus(this.objectContent);

		if(this.objectContent && this.interceptObject){
			if(this.objectContent.onRollOver)
				this.interceptObject.onRollOver= this.objectContent.onRollOver;

			if(this.objectContent.onRollOut)
				this.interceptObject.onRollOut = this.objectContent.onRollOut;

			if(this.objectContent.onPress){
				if (!this.interceptButtonObject){
					this.interceptButtonObject = new Image();
					this.interceptButtonObject.parent = this.interceptObject;
				}
				this.interceptButtonObject.onPress = this.objectContent.onPress;
			}

			if(this.objectContent.onRelease) {
				if (!this.interceptButtonObject){
					this.interceptButtonObject = new Image();
					this.interceptButtonObject.parent = this.interceptObject;
				}
				this.interceptButtonObject.onRelease = this.objectContent.onRelease;
			}

			if (this.interceptButtonObject){
				this.interceptButtonObject.x = this.objectContent.x;
				this.interceptButtonObject.y = this.objectContent.y;
				this.interceptButtonObject.width = this.objectContent.width;
				this.interceptButtonObject.height = this.objectContent.height;
				this.interceptButtonObject.opacity  = this.objectContent.opacity;
				this.interceptButtonObject.depth = this.objectContent.depth;
			}
		}
	};

	function hideObject(){
		if(this.objectContent)
			this.objectContent.playing = false;

		rnmc_stdMediaObject_hideObject();
	};

	function applyPositionChanges(){
		rnmc_stdMediaObject_applyPositionChanges();
		if(this.objectContent){
			if (this.interceptButtonObject){
				this.interceptButtonObject.x = this.objectContent.x;
				this.interceptButtonObject.y = this.objectContent.y;
				this.interceptButtonObject.width = this.objectContent.width;
				this.interceptButtonObject.height = this.objectContent.height;
				this.interceptButtonObject.opacity  = this.objectContent.opacity;
				this.interceptButtonObject.depth = this.objectContent.depth;
				this.interceptButtonObject.visible = this.objectContent.visible;
			}
		}
	}	

	function buttonDispatcher(btnId){
		switch(btnId){
		default:
			rnmc_stdMediaObject_buttonDispatcher(btnId);
		}
	}

//	=======================================  EVENT HANDLERS	===================================
//  обработчики специфичных для flash-событий
	function onFSCommandAlias(){
		onFSCommand();
	}

	function onFSCommand(){
//trace("rnmc_stdFlash.onFSCommand: command==" + Event.command + "; parameters==" + Event.parameters);
		var dispatcher = parent;
		while (dispatcher) {
			if ("dispatchAction" in dispatcher)
				break;
			dispatcher = dispatcher.parent;
		}

		if (!dispatcher)
			return;

		switch(Event.command){
		case "onEnterZone":
			if(this.onEnterZoneActions){
				for(var i = 0; i < this.onEnterZoneActions.length; i++){
					if(this.onEnterZoneActions[i].eventParam
						&& this.onEnterZoneActions[i].eventParam == Event.parameters){
						dispatcher.dispatchAction(this.onEnterZoneActions[i]);
					}
				}
			}
			break;
		case "onLeaveZone":
			if(this.onLeaveZoneActions){
				for(var i = 0; i < this.onLeaveZoneActions.length; i++){
					if(this.onLeaveZoneActions[i].eventParam
						&& this.onLeaveZoneActions[i].eventParam == Event.parameters){
						dispatcher.dispatchAction(this.onLeaveZoneActions[i]);
					}
				}
			}
			break;
		case "onPressZone":
			if(this.onPressZoneActions){
				for(var i = 0; i < this.onPressZoneActions.length; i++){
					if(this.onPressZoneActions[i].eventParam
						&& this.onPressZoneActions[i].eventParam == Event.parameters){
						dispatcher.dispatchAction(this.onPressZoneActions[i]);
					}
				}
			}
			break;
		case "onReleaseZone":
			if(this.onReleaseZoneActions){
				for(var i = 0; i < this.onReleaseZoneActions.length; i++){
					if(this.onReleaseZoneActions[i].eventParam
						&& this.onReleaseZoneActions[i].eventParam == Event.parameters){
						dispatcher.dispatchAction(this.onReleaseZoneActions[i]);
					}
				}
			}
			break;
		}
		if(this.onFSCommandActions){
			for(var i = 0; i < this.onFSCommandActions.length; i++){
				if(this.onFSCommandActions[i].eventParam
					&& this.onFSCommandActions[i].eventParam == Event.command){
					if(Event.command == "interrupted" || Event.command == "complete"){ //	совместимость c МХК
						if(this.onFSCommandActions[i][0] == "setCurrentStepResult"){
							var newAction = new Array();
							var actionParam = 0; 
							if(this.onFSCommandActions[i][1] == "%1"){
								actionParam = Event.parameters;
								this.objectResult = parseInt(Event.parameters);
							} else {
								actionParam = this.onFSCommandActions[i][1];
								this.objectResult = parseInt(this.onFSCommandActions[i][1]);
							}
//							newAction.push("setCurrentStepResult", actionParam);
//							dispatcher.dispatchAction(newAction);
						} else {
							dispatcher.dispatchAction(this.onFSCommandActions[i]);
						}
					}else {
						dispatcher.dispatchAction(this.onFSCommandActions[i]);
					}
				}
			}
		}
	}

	function getResult(resultsArray){
		if(this.onFSCommandActions){
			for(var i = 0; i < this.onFSCommandActions.length; i++){
				if(Event.command == "interrupted" || Event.command == "complete"){
					if(this.onFSCommandActions[i][0] == "setCurrentStepResult"){
						var resultString = this.objectResult + ";1.0";
						resultsArray.push(resultString);
						break;
					}
				}
			}
		}

		rnmc_stdObject_getResult(resultsArray);	
	}
]]></script>
</composition>
</rmml>