Sunday, March 15, 2009

How to play mp3 from Flex

<?xml version="1.0" encoding="utf-8"?><mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" >
<mx:Button x="221" y="181" label="Play" width="99" height="26" click="playSound()"/> <mx:Button x="221" y="281" label="Stop" width="99" height="26" click="stopSound()"/> <mx:Script>
<![CDATA[
import flash.trace.Trace;
import mx.core.SoundAsset;
import flash.media.*;
import mx.controls.Alert;

[Embed(source="media/KissfromaRose.mp3")]
[Bindable] public var Song:Class;

public var mySong:SoundAsset = new Song() as SoundAsset;
public var channel:SoundChannel;

public function playSound():void {
// Make sure we don't get multiple songs playing at the same time
stopSound();
// Play the song on the channel channel = mySong.play();
}

public function stopSound():void {
// Stop the channel, but only if it exists
if ( channel != null )
channel.stop();
}
]]>
</mx:Script>
</mx:Application>


How to call Webservice from flex

<![CDATA[
import mx.rpc.events.FaultEvent;
import mx.managers.CursorManager;
import flash.trace.Trace;
import mx.controls.Alert;
import mx.rpc.events.ResultEvent;
import mx.rpc.soap.WebService;

private function callSOAP():void{
var service:WebService = new WebService();
service.wsdl = "http://localhost:8080/webproject/services/UserLogin?wsdl";
service.getUserdetails.addEventListener("result",userDetailsResultfunction);
service.loadWSDL();
service.getUserdetails("argument1","argument2");
}
private function userDetailsResultfunction(event:ResultEvent):void{
var xmlResult:XML;
xmlResult = XML(event.result);
Alert.show("Result : " + xmlResult.toString());
}
]]>