<?xml version="1.0"?>
<project name="AS3 Compile" default="launch" basedir="./">
	<property file="build.properties"/>
	
	<target name="launch" depends="build">
		<condition property="runtarget" value="launchtab">
			<equals arg1="${launchmethod}" arg2="tab" />
		</condition>
		<condition property="runtarget" value="launchstandalone">
			<equals arg1="${launchmethod}" arg2="standalone" />
		</condition>
		<condition property="runtarget" value="launchhtml">
			<equals arg1="${launchmethod}" arg2="html" />
		</condition>
		<antcall target="${runtarget}" />
	</target>
	
	<target name="build" depends="compile">
		<basename file="${output.file}" property="basefilename" suffix=".swf"/>
		<antcall target="copyswf" />
		<!-- remove following line to avoid creation of html file -->
		<antcall target="copyhtml" />
		<antcall target="document" />
	</target>
	
	<target name="compile">
	    <exec executable="${flex2.dir}/${compiler}">
	    	<arg line="-default-frame-rate=${framerate}" />
	    	<arg line="-default-background-color=0x${background.color}" />
			<arg line="-default-size ${width} ${height}" />
		    <arg line="'${basedir}/${source.dir}/${source.file}'" />
			<arg line="-o=${output.file}"/>
	    </exec>
		<condition property="builddocument">
			<equals arg1="${docbuild}" arg2="true" />
		</condition>
	</target>
	
	<target name="copyswf">
		<mkdir dir="${deploy.dir}"/>
		<move file="${output.file}" todir="${basedir}/${deploy.dir}"/>
	</target>
	
	<target name="copyhtml">
		<delete file="${basedir}/${deploy.dir}/${basefilename}.html" />
		<filter token="basefilename" value="${basefilename}" />
		<filter token="width" value="${width}" />
		<filter token="height" value="${height}" />
		<filter token="color" value="${background.color}" />
		<copy file="html_template/template.html" tofile="${basedir}/${deploy.dir}/${basefilename}.html" filtering="true" />
		<copy file="html_template/swfobject.js" tofile="${basedir}/${deploy.dir}/swfobject.js" />
	</target>
	
	<target name="document" if="builddocument">
		<exec executable="${asdoc.dir}/${documenter}">
			<arg line="-source-path ${source.dir} -doc-sources ${source.dir}/. -main-title ${doc.maintitle} -window-title ${doc.windowtitle} -output ${doc.dir}"/>
		</exec>
	</target>
	
	<target name="launchtab">
		<exec executable="${flashdevelop}" spawn="true">
			<arg line="'${basedir}/${deploy.dir}/${output.file}'" />
		</exec>
	</target>
	
	<target name="launchstandalone">
		<exec executable="${flex2.dir}/${saplayer}" spawn="true">
			<arg line="${basedir}/${deploy.dir}/${output.file}" />
		</exec>
	</target>	

	<target name="launchhtml">
		<exec executable="${browser}" spawn="true">
			<arg line="${deploy.dir}/${basefilename}.html" />
		</exec>
	</target>
	
</project>
