Embedding sound in Flex4


 

Embedding sound in Flex4

You can embedded and play mp3 sound in flex application.

You can embedded and play mp3 sound in flex application.

Embedding sound in Flex4:

You can embedded and play mp3 sound in flex application. In this example we have used two buttons to play and stop the music. In this example you will see how we can embedded a sound in a flex application.

Example:

<?xml version="1.0" encoding="utf-8"?>

<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009"

xmlns:s="library://ns.adobe.com/flex/spark"

xmlns:mx="library://ns.adobe.com/flex/mx"

minWidth="955" minHeight="600">

<fx:Script>

<![CDATA[

import flash.media.*;

[Embed(source="C:/work/bikrant/mp3/tone.mp3")]

[Bindable]

public var soundcls:Class;

public var soundmp3:Sound = new soundcls() as Sound;

public var soundchannel:SoundChannel;

public function play():void {

soundchannel=soundmp3.play();

}

public function stop():void {

soundchannel.stop();

}

]]>

</fx:Script>

<s:Panel title="Embedding Sound Example"

chromeColor="#000000"

color="#CCCCCC"

width="332" height="211">

<mx:Image id="GlobeImage"

source="@Embed(source='C:/work/bikrant/image/player.png')"

x="100" y="0"/>

<s:Button label="Play Sound" click="play()" x="68" y="136"/>

0

<s:Button label="Stop" click="stop()" x="179" y="136"/>

</s:Panel>

</s:Application>

1

Output:

Running Application:

To view this page ensure that Adobe Flash Player version 10.0.0 or greater is installed.

Download this code

Ads