changeset 737:18974af682cf

* Tweaks to event strings for safety * Fixed mis-firing event in Bridge * Added a simple example * Added packaging
author mas01mj
date Thu, 16 Sep 2010 11:39:52 +0000
parents e7cf6b9c7944
children d9f263d95b64
files bindings/as3/build.properties bindings/as3/build.xml bindings/as3/build/as3bridge.swf bindings/as3/examples/simpletest/build.properties bindings/as3/examples/simpletest/build.xml bindings/as3/examples/simpletest/src/Example.as bindings/as3/src/org/omras2/audiodb/Bridge.as bindings/as3/src/org/omras2/audiodb/LookupEvent.as bindings/as3/src/org/omras2/audiodb/SearchEvent.as bindings/as3/src/org/omras2/audiodb/SoundEvent.as
diffstat 10 files changed, 122 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/bindings/as3/build.properties	Wed Sep 15 16:23:45 2010 +0000
+++ b/bindings/as3/build.properties	Thu Sep 16 11:39:52 2010 +0000
@@ -13,4 +13,8 @@
 
 project.class = ${src.dir}/Main.as
 project.swf = as3bridge.swf
+project.swc = as3bridge.swc
 
+example.dir = example
+example.class = ${example.dir}/Example.as
+example.swf = example.swf
--- a/bindings/as3/build.xml	Wed Sep 15 16:23:45 2010 +0000
+++ b/bindings/as3/build.xml	Thu Sep 16 11:39:52 2010 +0000
@@ -32,5 +32,14 @@
 		</exec> 
 	</target>
 	
+	<target name="package">
+		<mkdir dir="lib" />
+		<compc output="lib/${project.swc}" 
+			include-classes="org.omras2.audiodb.Bridge">
+			<source-path path-element="${src.dir}"/>
+			<source-path path-element="ext" />
+		</compc>
+	</target>
+	
 	<target name="compile-and-launch" depends="compile,launch" />
 </project>
Binary file bindings/as3/build/as3bridge.swf has changed
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/bindings/as3/examples/simpletest/build.properties	Thu Sep 16 11:39:52 2010 +0000
@@ -0,0 +1,15 @@
+flex.dir = /Applications/eclipse36/plugins/com.powerflasher.fdt.shippedflex_3.3.0.4852_1001/flex/
+
+src.dir = src
+
+compiler.as3				= true
+compiler.strict				= true
+compiler.warnings			= true
+compiler.benchmark			= true
+compiler.use-network 		= true
+compiler.encoding			= UTF-8
+compiler.config				= ${flex.dir}/frameworks/flex-config.xml
+FLEX_HOME=${flex.dir}
+
+project.class = ${src.dir}/Example.as
+project.swf = simpletest.swf
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/bindings/as3/examples/simpletest/build.xml	Thu Sep 16 11:39:52 2010 +0000
@@ -0,0 +1,36 @@
+<?xml version="1.0" encoding="utf-8"?>
+
+<project name="simpletest" basedir=".">
+
+	<property file="build.properties" />
+	<taskdef resource="flexTasks.tasks" classpath="${FLEX_HOME}/ant/lib/flexTasks.jar" />
+
+	<target name="compile">
+		<mkdir dir="build" />
+		
+		<mxmlc file="${project.class}" target-player="10.0.0" output="build/${project.swf}" compiler.as3="${compiler.as3}" compiler.optimize="true" compiler.strict="${compiler.strict}" actionscript-file-encoding="${compiler.encoding}" keep-generated-actionscript="${compiler.keep-generated-as}" incremental="false" benchmark="${compiler.benchmark}" debug="true" use-network="${compiler.use-network}" warnings="${compiler.warnings}" fork="false">
+			<source-path path-element="${src.dir}" />
+			<compiler.include-libraries dir="../../lib" append="true">
+				<include name="as3bridge.swc" />
+			</compiler.include-libraries> 			 
+		</mxmlc>
+	</target>
+	
+	
+	<condition property="launch.executable" value="cmd" else="open">
+		<os family="windows" />
+	</condition>
+
+	<condition property="launch.argline" value="/c start " else="">
+		<os family="windows" />
+	</condition>
+	
+	<target name="launch">
+		<exec executable="${launch.executable}" dir="." spawn="true">
+			<arg line="${launch.argline}" />
+			<arg line="build/${project.swf}" />
+		</exec> 
+	</target>
+	
+	<target name="compile-and-launch" depends="compile,launch" />
+</project>
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/bindings/as3/examples/simpletest/src/Example.as	Thu Sep 16 11:39:52 2010 +0000
@@ -0,0 +1,54 @@
+package  
+{
+	
+	import org.omras2.audiodb.Bridge;
+	import org.omras2.audiodb.SearchEvent;
+	import org.omras2.audiodb.SoundEvent;
+	import org.omras2.audiodb.model.SearchResult;
+
+	import flash.display.Sprite;
+	import flash.media.Sound;
+	/**
+	 * @author mikej
+	 */
+	public class Example extends Sprite 
+	{
+		private var _bridge : Bridge;
+		private var _sounds : Array;
+
+		public function Example()
+		{
+			this._bridge = new Bridge("http://0.0.0.0:8080");
+			this._sounds = [];
+			
+			// Find the tracks similar to AWAL1000
+			_bridge.addEventListener(SearchEvent.COMPLETE, this.handleSearchComplete);
+			_bridge.search("AWAL1000");
+		}
+
+		private function handleSearchComplete(event : SearchEvent) : void 
+		{
+			// Now grab the first 20s of the first result
+			_bridge.addEventListener(SoundEvent.COMPLETE, this.handleSoundLoaded);
+			
+			var query : SearchResult = (event.results[0] as SearchResult);
+			_bridge.getSound(query.uid, query.ipos, 5);
+			
+			var closestMatch : SearchResult = event.results[1] as SearchResult;
+			
+			_bridge.getSound(closestMatch.uid, closestMatch.ipos , 5);
+		}
+
+		private function handleSoundLoaded(event : SoundEvent) : void 
+		{
+			_sounds.push(event.sound);
+			if(_sounds.length == 2)
+			{
+				for each(var sound : Sound in _sounds)
+				{
+					sound.play();		
+				}
+			}
+		}
+	}
+}
--- a/bindings/as3/src/org/omras2/audiodb/Bridge.as	Wed Sep 15 16:23:45 2010 +0000
+++ b/bindings/as3/src/org/omras2/audiodb/Bridge.as	Thu Sep 16 11:39:52 2010 +0000
@@ -108,7 +108,7 @@
 				{
 					results.push(SearchResult.createFromResponse(result));
 				}
-				this.dispatchEvent(new SearchEvent(LookupEvent.COMPLETE, results));
+				this.dispatchEvent(new SearchEvent(SearchEvent.COMPLETE, results));
 			}
 		}
 		
--- a/bindings/as3/src/org/omras2/audiodb/LookupEvent.as	Wed Sep 15 16:23:45 2010 +0000
+++ b/bindings/as3/src/org/omras2/audiodb/LookupEvent.as	Thu Sep 16 11:39:52 2010 +0000
@@ -9,7 +9,7 @@
 	 */
 	public class LookupEvent extends Event 
 	{
-		public static const COMPLETE : String = "complete";
+		public static const COMPLETE : String = "lookupComplete";
 		
 		private var _track : Track;
 
--- a/bindings/as3/src/org/omras2/audiodb/SearchEvent.as	Wed Sep 15 16:23:45 2010 +0000
+++ b/bindings/as3/src/org/omras2/audiodb/SearchEvent.as	Thu Sep 16 11:39:52 2010 +0000
@@ -7,7 +7,7 @@
 	 */
 	public class SearchEvent extends Event 
 	{
-		public static const COMPLETE : String = "complete";
+		public static const COMPLETE : String = "searchComplete";
 		private var _results : Array;
 		
 		public function SearchEvent(type : String, results : Array, bubbles : Boolean = false, cancelable : Boolean = false)
--- a/bindings/as3/src/org/omras2/audiodb/SoundEvent.as	Wed Sep 15 16:23:45 2010 +0000
+++ b/bindings/as3/src/org/omras2/audiodb/SoundEvent.as	Thu Sep 16 11:39:52 2010 +0000
@@ -8,7 +8,7 @@
 	 */
 	public class SoundEvent extends Event 
 	{
-		public static const COMPLETE : String = "complete";
+		public static const COMPLETE : String = "soundLoaded";
 		private var _sound : Sound;
 		
 		public function SoundEvent(type : String, sound : Sound, bubbles : Boolean = false, cancelable : Boolean = false)