How to control an m4a file - actionscript-3

I am playing m4a files that require that I use a NetStream object and want to control the audio with a SoundChannel object (because that is the only way I know to sync an HSlider control with an audio file). My problem is that I cannot connect the Sound Channel with the audio source. The event handler button1_clickHandler does not even regognize the existance of the SoundChannel object. Is there a way to control this type of audio file with a SoundChannel? If not, how can I set the position of the HSlider-- I've tried using HSlider.value, but that somehow gets overridden.
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" minWidth="955" minHeight="600" creationComplete="init()">
<mx:Script>
<![CDATA[
private var audioExample:AudioExample_M4A;
public function init():void{
audioExample = new AudioExample_M4A();
}
private function button1_clickHandler(event:MouseEvent):void{
if(audioExample.soundChannel){
audioExample.soundChannel.stop()
trace("Yes")
}else{
trace("No")
}
}
]]>
</mx:Script>
<mx:Button label="Play / Pause" click="button1_clickHandler(event)"/>
</mx:Application>
Here is the class file AudioExample_M4A.as:
package {
import flash.display.Sprite;
import flash.events.*;
import flash.media.SoundChannel;
import flash.media.Video;
import flash.net.NetConnection;
import flash.net.NetStream;
public class AudioExample_M4A extends Sprite {
public var soundChannel:SoundChannel= new SoundChannel();;
public var temp:String = new String()
public var audioURL:String = "badge.m4a";
private var connection:NetConnection;
public var stream:NetStream;
public function AudioExample_M4A() {
connection = new NetConnection();
connection.addEventListener(NetStatusEvent.NET_STATUS, netStatusHandler);
connection.connect(null);
}
private function netStatusHandler(event:NetStatusEvent):void {
switch (event.info.code) {
case "NetConnection.Connect.Success":
connectStream();
break;
case "NetStream.Play.StreamNotFound":
break;
}
}
private function connectStream():void {
stream = new NetStream(connection);
stream.addEventListener(NetStatusEvent.NET_STATUS, netStatusHandler);
stream.client={onMetaData:function(obj:Object):void{
trace("metadata: duration=" + obj.duration);
}
}
soundChannel = stream.play(audioURL) as SoundChannel;
}
}}

You cannot control a NetStream object with a SoundChannel object. These are two completely different methods to playing media and, as far as I know, do not share a common base.
To allow for a slider to control the pointer position, you need to do the following:
Get the slider position as a percentage (slider.position * slider.minimum/slider.maximum in Spark, not sure about in MX)
Get the duration of the song. This is retrieved via NetStream.onMetaData
Call NetStream.seek() with an argument of slider percentage multiplied by duration (seek() expects the value in seconds). So NetStream.seek( duration * positionPercentage )

Related

Flex Background Worker disposing of failed MessageChannel freezes application

I have the following scenario: I am using a MessageChannel to communicate with a background worker in a flex application. Since the code is to eventually be transformed into a library, it should also be able to handle malformed input (e.g. sending classes via the channel for which no class alias is registered in the background worker). In this case I want to abort the worker. My code is the following:
package
{
import flash.display.Sprite;
import flash.events.Event;
import flash.system.MessageChannel;
import flash.system.Worker;
public class BW extends Sprite
{
/** Incoming channel */
private var fromCoordinatorChannel:MessageChannel;
/** Outgoing channel */
private var toCoordinatorChannel:MessageChannel;
public function BW()
{
super();
initChannels();
}
/**
* Get channels from shared property and attach event listener
*/
private function initChannels():void {
// Get channnels from shared property
fromCoordinatorChannel = Worker.current.getSharedProperty("toWorkerChannel");
toCoordinatorChannel = Worker.current.getSharedProperty("fromWorkerChannel");
// Attach event listener for incoming messages
fromCoordinatorChannel.addEventListener(Event.CHANNEL_MESSAGE, onIncomingMessage);
}
/**
* Event handler for incoming messages on the channel.
* #param event Event that came in
*/
private function onIncomingMessage(event:Event):void {
handleIncoming();
}
/**
* Get oldest message from channel and handle it
*/
private function handleIncoming():void {
if(fromCoordinatorChannel.messageAvailable) {
try {
var wm:Object = fromCoordinatorChannel.receive(true);
} catch(e:Error) {
fromCoordinatorChannel.close();
trace("Invalid type of package sent - could not be deserialized.");
// Kill myself
fromCoordinatorChannel = null;
toCoordinatorChannel = null;
Worker.current.setSharedProperty("toWorkerChannel", null);
Worker.current.setSharedProperty("fromWorkerChannel", null);
Worker.current.terminate();
}
}
}
}
}
And in the primordial worker:
<?xml version="1.0" encoding="utf-8"?>
<s:WindowedApplication xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
xmlns:mx="library://ns.adobe.com/flex/mx">
<fx:Script>
<![CDATA[
import mx.events.FlexEvent;
var worker:Worker;
var to:MessageChannel;
var from:MessageChannel;
var graveyard:Array = new Array();
private function removeWorkerIfFailed():void {
if(worker && worker.state == WorkerState.TERMINATED) {
from.close();
worker = null;
// What the actual f***? If I allow this channel to be garbage collected, it breaks. If I prevent that, it doesn't (o.Ó)
graveyard.push(to);
to = null;
from = null;
}
}
protected function button1_clickHandler(event:MouseEvent):void
{
registerClassAlias("Example", Example);
// Create worker and channels
worker = WorkerDomain.current.createWorker(Workers.BW);
to = Worker.current.createMessageChannel(worker);
from = worker.createMessageChannel(Worker.current);
// Attach event listener to status of worker so its reference can be deleted when it fails
worker.addEventListener(Event.WORKER_STATE,function(event:Event):void {removeWorkerIfFailed();});
// Set shared properties so worker can access channels
worker.setSharedProperty("toWorkerChannel", to);
worker.setSharedProperty("fromWorkerChannel", from);
// Attach event listener for incoming messages
from.addEventListener(Event.CHANNEL_MESSAGE, function(event:Event):void { trace('incoming'); });
// Start the worker
worker.start();
var example1:Example = new Example("one");
to.send(example1);
}
]]>
</fx:Script>
<s:Button label="Do it" click="button1_clickHandler(event)">
</s:Button>
</s:WindowedApplication>
Add the Example class
package
{
import flash.utils.IDataInput;
import flash.utils.IDataOutput;
import flash.utils.IExternalizable;
public class Example implements IExternalizable
{
public var name:String;
public function Example(name:String)
{
this.name = name;
}
public function readExternal(input:IDataInput):void
{
name = input.readUTF();
}
public function writeExternal(output:IDataOutput):void
{
output.writeUTF(name);
}
}
}
The problem is the following: If I remove the line in the removeWorkerIfFailed() that pushes a reference to the array (thereby preventing the channel from being garbage collected), the main application freezes. The debugger does not show any active function calls. As long as that line is there, everything works fine.
To reiterate: I know that in order to fix it, I need to call the registerClassAlias(...) also in the background worker, but I am trying to handle precisely this case that someone throws something wrong at the background worker.
Thank you

Can't display video coming in from NetStream properly

I am basically starting work with Flex and netstream for video calls. So I was able to read a bit about Netstreams and streaming and I wrote this code to get my camera and publish my stream in a video display below in the view but even though I pass through all the methods without any error, the display is not showing so I don't really know what's going on. Here is what I did.
<?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" applicationDPI="160" creationComplete="start();">
<fx:Script>
import flash.media.Camera;
import flash.media.Video;
import flash.net.NetConnection;
import flash.net.ObjectEncoding;
import flash.events.AsyncErrorEvent;
import flash.events.NetStatusEvent;
import flash.net.NetStream;
import mx.graphics.ImageSnapshot;
import mx.graphics.codec.JPEGEncoder;
public var camera:Camera;
var video:Video;
public var myVideo:Video;
private var nc:NetConnection;
private var rtmpf:String="rtmfp://p2p.rtmfp.net/61c33c80be7022350a0dea3d-960194f988ba/";
private const DEVKEY:String = "61c33c80be7022350a0dea3d-960194f988ba";
public var in_ns:NetStream;
public var out_ns:NetStream;
public function start():void{
trace("Started the start function");
nc=new NetConnection();
nc.objectEncoding = ObjectEncoding.AMF0;
nc.client=this;
nc.addEventListener(NetStatusEvent.NET_STATUS, netStatusHandler);
nc.connect(rtmpf);
}
public function netStatusHandler(event:NetStatusEvent):void{
switch(event.info.code){
case "NetConnection.Connect.Success":
trace("Received the status");
initStart();
default:
trace( event.info.code);
}
}
public function initStart():void{
trace("Started the initstart function");
initNetStream();
initMyVideo();
publish();
playIt();
}
public function initNetStream():void{
trace("Started the initNetstream start function");
out_ns=new NetStream(nc);
out_ns.client=this;
in_ns=new NetStream(nc);
in_ns.client=this;
}
public function publish():void{
trace("Started the publish function");
camera=Camera.getCamera();
out_ns.attachCamera(camera);
out_ns.publish("Me", "live");
}
public function startCamera(muteCam:Boolean=false):void{
if(!video)
video = new Video();
trace("Started the startCamera function");
camera=Camera.getCamera();
if(muteCam){
video.attachCamera(camera);
//out_ns.attachCamera(camera);
//out_ns.publish("Me", "live");
vidHolder.addChild(video);
}else{
video.attachCamera(null);
if(contains(video))
vidHolder.removeChild(video);
//camera=null;
}
}
public function initMyVideo():void
{
trace("Started the initmyvideo function");
myVideo = new Video(230,160);
myVideo.x = 10;
myVideo.width = 230;
myVideo.height = 160;
myVideo.y = 30;
// myVid.addChild(myVideo);
}
public function playIt():void{
trace("Started the play it function");
myVideo.attachNetStream(in_ns);
in_ns.play("Me");
myVid.addChild(myVideo);
}
public function stopCamera():void{
vidHolder.removeChild(video);
}
</fx:Script>
<fx:Declarations>
<!-- Place non-visual elements (e.g., services, value objects) here -->
</fx:Declarations>
<s:Button x="116" y="28" label="Start" click="startCamera(true)"/>
<s:VideoDisplay id="vidHolder" x="31" y="87" width="200" height="100"
/>
<s:VideoDisplay id="myVid" x="31" y="250"/>
<s:Button id="stop" x="208" y="28" label="Stop" click="startCamera(false)"/>
</s:Application>
These are some reasons that is stopping from displaying the stream.
Are you testing it on the same browser using your same webcam device
driver ?
Possibility is that you were not able to see it maybe since the driver is being used.
Get a virtual webcam driver from a website ManyCam and test it out. Your application will work.

How to add in .as with a package int MXML

How to add in .as with a class extends Sprite ??
We created the Easy1 in Flash Professional to create a live streaming video viaFMS for 2 users and now we want to combine easy1 into HelloFlerry to invoke Flash-Java nativeprocess.
<?xml version="1.0" encoding="utf-8"?>
<s:WindowedApplication 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="600" minHeight="400"
xmlns:flerry="net.riaspace.flerry.*"
xmlns:easy1="Easy1.*">
<easy1:Easy1 label="Easy1"/>
<easy1:Script source="Easy1.as"/>
package Easy1
{
import flash.display.Sprite;
import flash.events.NetStatusEvent;
import flash.net.NetConnection;
import flash.net.NetStream;
import flash.media.Camera;
import flash.media.Microphone;
import flash.media.Video;
public class Easy1 extends Sprite
{
private var nc:NetConnection;
private var good:Boolean;
private var rtmpNow:String;
private var nsIn:NetStream;
private var nsOut:NetStream;
private var cam:Camera;
private var mic:Microphone;
private var vidLocal:Video;
private var vidStream:Video;
public function Easy1()
{
trace("Hello testing");
rtmpNow = "rtmp://localhost/LiveStreams";
nc=new NetConnection();
nc.connect(rtmpNow);
nc.addEventListener(NetStatusEvent.NET_STATUS,checkCon);
setCam();
setMic();
setVideo();
}
private function checkCon(e:NetStatusEvent):void
{
good = e.info.code == "NetConnection.Connect.Success";
if (good)
{
nsOut = new NetStream(nc);
nsOut.attachAudio(mic);
nsOut.attachCamera(cam);
nsOut.publish("left","live");
nsIn = new NetStream(nc);
nsIn.play("right");
vidStream.attachNetStream(nsIn);
}
}
private function setCam()
{
cam = Camera.getCamera();
cam.setKeyFrameInterval(9);
cam.setMode(240,180,15);
cam.setQuality(0,80);
}
private function setMic()
{
mic = Microphone.getMicrophone();
mic.gain = 85;
mic.rate = 11;
mic.setSilenceLevel(15,2000);
}
private function setVideo()
{
vidLocal = new Video(cam.width,cam.height);
addChild(vidLocal);
vidLocal.x = 15;
vidLocal.y = 30;
vidLocal.attachCamera(cam);
vidStream = new Video(cam.width,cam.height);
addChild(vidStream);
vidStream.x=(vidLocal.x+ cam.width +10);
vidStream.y = vidLocal.y;
}
}
}
MXML is a template, which effectively creates package declaration for you, so once you try to add one of your own, you will duplicate package definitions, which is not allowed.
You can't also declare classes inside <Script> tag. The code from <Script> tag goes into methods and properties definition block of the class.
If you must declare package and class - use *.as file for that. If you want them to be declared for you using MXML template - well, then don't declare them yourself. You can't have both at the same time.

Need to process the return string from a URLLoader.load call

I have the requirement in a Flex application to create & populate an object from the return from a call to a URL. Here is what I need to be able to do:
I have a class which communicates with the web server.
I have a function in this class (called getPerson) which would return a Person object which is populated from the XML data returned from the web server.
The problem I am running into (and it seems this is a very common problem, but I have not seen a solution which I can see would work) is that the load method of the URLLoader is asynchronous.
I have an event listener firing on the Event.COMPLETE event which parses the XML and populates my object in the event handler, but how would I get this object back to my originating code in my application which originally called my getPerson function?
So by the time the return from the server comes back, my method is finished and I cannot return my populated Person object.
My question is how can I accomplish this? I am still fairly new to ActionScript and have been spinning my wheels for a day now on this.
I've added some sample code which demonstrates the problem I am having - I have simplified what I am using:
MXML application file:
<?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"
creationComplete="application1_creationCompleteHandler(event)">
<fx:Script>
<![CDATA[
import mx.events.FlexEvent;
protected function application1_creationCompleteHandler(event:FlexEvent):void
{
var d:DAL = new DAL();
d.CreateNewPerson( "John Smith" );
}
]]>
</fx:Script>
<fx:Declarations>
<!-- Place non-visual elements (e.g., services, value objects) here -->
</fx:Declarations>
</s:Application>
DAL.cs file:
package
{
import flash.events.Event;
import flash.net.URLLoader;
import flash.net.URLRequest;
import flash.net.URLRequestMethod;
import mx.controls.Alert;
public class DAL
{
public function DAL()
{
}
public function CreateNewPerson( Name:String ):void
{
var strXML:String = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>";
var loader:URLLoader = new URLLoader();
loader.addEventListener(Event.COMPLETE, onPostComplete);
var request:URLRequest = new URLRequest( "http://www.cnn.com" );
request.method = URLRequestMethod.POST;
request.data = strXML;
loader.load(request);
}
private function onPostComplete( evt:Event ):void
{
//Process returned string
//Here is where I need to return my object
var obj:Object = new Object()
}
}
}
What I need to do is somehow get the "obj" variable back out to my MXML application file so I can use it there.
Thanks in advance!
On your mxml application file:
var d:DAL = new DAL();
protected function application1_creationCompleteHandler(event:FlexEvent):void
{
d.CreateNewPerson( "John Smith" );
d.addEventListener('PersonCreated', personCreated);
}
private function personCreated(evt:Event) :void
{
var obj:Object = new Object();
obj = d.ojectToBeReturned;
// obj will contain the object from your class...
}
On your DAL class, declare the object variable and create a getter/setter function, i.e.
private var _myObjectToBeReturned:Object;
public function get ojectToBeReturned() :Object
{
return _myObjectToBeReturned;
}
And on your method
private function onPostComplete( evt:Event ):void
{
//Here is where I need to return my object
_myObjectToBeReturned = new Object();
// Perform the process for the object.
// Call the event from your parent.
this.dispatchEvent(new Event('PersonCreated'));
}
your main MXML file
<fx:Script>
<![CDATA[
import flash.events.Event;
import mx.events.FlexEvent;
protected function application1_creationCompleteHandler(event:FlexEvent):void
{
var d:DAL = new DAL();
d.addEventListener(Event.COMPLETE, onLoadComplete);
d.CreateNewPerson( "John Smith" );
}
private function onLoadComplete(e:Event):void
{
trace("DATA LOADED")
}
]]>
</fx:Script>
and your DAL.as
package
{
import flash.events.Event;
import flash.events.EventDispatcher;
import flash.events.IEventDispatcher;
import flash.events.IOErrorEvent;
import flash.events.SecurityErrorEvent;
import flash.net.URLLoader;
import flash.net.URLRequest;
import flash.net.URLRequestMethod;
import mx.controls.Alert;
/**
* ...
* #author Jeet Chauhan
*/
public class DAL implements IEventDispatcher
{
private var dispatcher:IEventDispatcher;
public function DAL() {
dispatcher = new EventDispatcher();
}
public function CreateNewPerson( Name:String ):void {
/*var strXML:String = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>";
var loader:URLLoader = new URLLoader();
loader.addEventListener(Event.COMPLETE, onPostComplete);
loader.addEventListener(IOErrorEvent.IO_ERROR, onPostComplete);
loader.addEventListener(SecurityErrorEvent.SECURITY_ERROR, onPostComplete);
var request:URLRequest = new URLRequest( "http://www.cnn.com" );
request.method = URLRequestMethod.POST;
request.data = strXML;
loader.load(request);*/
// let assume data loaded and onPostComplete called
onPostComplete(new Event(Event.COMPLETE));
}
private function onPostComplete(evt:Event):void {
//Process returned string
//Here is where I need to return my object
var obj:Object = new Object()
dispatchEvent(evt);
}
/* INTERFACE flash.events.IEventDispatcher */
public function dispatchEvent(event:Event):Boolean
{
return dispatcher.dispatchEvent(event);
}
public function hasEventListener(type:String):Boolean
{
return dispatcher.hasEventListener(type);
}
public function willTrigger(type:String):Boolean
{
return dispatcher.willTrigger(type);
}
public function removeEventListener(type:String, listener:Function, useCapture:Boolean = false):void
{
dispatcher.removeEventListener(type, listener, useCapture);
}
public function addEventListener(type:String, listener:Function, useCapture:Boolean = false, priority:int = 0, useWeakReference:Boolean = false):void
{
dispatcher.addEventListener(type, listener, useCapture, priority, useWeakReference);
}
}
}
hope this help

Send data from popup to main application.

I'm not getting the answer I'm looking for.
I want to send the request data i get to the main application.
<?xml version="1.0" encoding="utf-8"?>
<mx:TitleWindow xmlns:mx="http://www.adobe.com/2006/mxml" remove="titlewindow1_removeHandler(event)"
width="400" height="220" layout="absolute" title="USER LOGIN">
<mx:Metadata>
[Event(name="commEvent", type="flash.events.Event")]
</mx:Metadata>
<mx:Script>
<![CDATA[
import data.Data;
import mx.events.FlexEvent;
import mx.managers.PopUpManager;
[Bindable]
public var userID:String;
private function loginUser():void{
trace("btn");
var req:URLRequest = new URLRequest('http://localhost/CCN/userProcess.php');
var loader:URLLoader = new URLLoader();
req.method="POST";
var variables:URLVariables = new URLVariables();
variables.email= username.text;
variables.password= password.text;
variables.action= "login_user";
req.data=variables;
loader.addEventListener(Event.COMPLETE,onDataLoaded);
loader.load(req);
}
protected function loginButton_clickHandler(event:MouseEvent):void
{
// TODO Auto-generated method stub
loginUser();
}
private function onDataLoaded(e:Event):void{
var xml:XML= new XML(e.target.data);
if(xml.status=="success"){
//SEND DATA TO MAIN APPLICATION ????
PopUpManager.removePopUp(this);
}else{
fail.visible=true;
username.text="";
password.text="";
username.setFocus();
}
}
protected function loginButton_keyDownHandler(ee:KeyboardEvent):void
{
// TODO Auto-generated method stub
if(ee.keyCode==13){
loginUser();
}
}
protected function titlewindow1_removeHandler(event:FlexEvent):void
{
// TODO Auto-generated method stub
}
]]>
</mx:Script>
<mx:TextInput id="username" x="141" y="31" width="199" text=""/>
<mx:TextInput keyDown="loginButton_keyDownHandler(event)" text="000" id="" x="141" y="84" width="199" displayAsPassword="true"/>
<mx:Button id="loginButton" x="275" y="133" label="LOGIN" click="loginButton_clickHandler(event)"/>
<mx:Label x="22" y="33" text="Email"/>
<mx:Label x="22" y="86" text="Password"/>
<mx:Label x="22" visible="false" y="135" id="fail" color="#FF0000" text="LOGIN FAILED"/>
</mx:TitleWindow>
here is the main application code
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
minWidth="955" minHeight="600" backgroundColor="#FFFFFF"
creationComplete="application1_creationCompleteHandler(event)" layout="absolute">
<mx:Script>
<![CDATA[
import mx.containers.TitleWindow;
import mx.core.IFlexDisplayObject;
import mx.events.CloseEvent;
import mx.events.FlexEvent;
import mx.managers.PopUpManager;
//private var loginWindow:TitleWindow;
public var user:String;
private var login:Login
private function application1_creationCompleteHandler(event:FlexEvent):void
{
// TODO Auto-generated method stub
login = Login(
PopUpManager.createPopUp(this, Login, true));
PopUpManager.centerPopUp(login);
//login['loginButton'].addEventListener(MouseEvent.CLICK,onClose);
login.addEventListener(CloseEvent.CLOSE,oncc)
}
private function onClose(e:Event):void{
trace("Trace : "+login.userID);
}
private function
]]>
</mx:Script>
</mx:Application>
I would recommend solving this by adding a custom event, as your tag implies you may understand.
If not, here are the steps you would follow.
1) Create a new Event type (extend the Event class in actionscript - be sure to override clone())
2) Add an event listener for your new Event type in the parent application on the popup
3) cause the popup to dispatch your new Event type before it closes
4) Handle whatever it is you're looking for (userID?) in the event handler.
I would recommend attaching the userID to the actual event, so that the parent is not directly addressing login.userID. From a loose coupling standpoint, it's more correct. That said, if you don't wish to, you can simplify the solution by NOT attaching the userID. Loose coupling is a great goal, but if you only plan to use this relationship once, it's not incredibly necessary.
If you choose to go the tighter coupling route, then you only have to dispatch an event with a custom "type" instead of an extended Event.
If you need a lower level example (less description, more code) let me know, and I can help with that as well.
The example provided below is the slightly more complex version, where you extend an event to contain the data.
Event class::
package mycomponents
{
import flash.events.Event;
public class CustomEvent extends Event
{
public static const EVENT_TYPE_NAME:String = "myEventType"
public var mUserID:String = "";
public var mSuccess:Boolean = false;
public function CustomEvent(aType:String, aUserID:String, aSuccess:Boolean)
{
super(aType)
mUserID = aUserID;
mSuccess = aSuccess;
}
override public function clone():Event
{
var lEvent:CustomEvent = new CustomEvent(mUserID, mSuccess);
return lEvent;
}
}
}
In Popup::
private var loginSuccessful:Boolean = false;
private function onDataLoaded(e:Event):void{
var xml:XML= new XML(e.target.data);
if(xml.status=="success"){
userID = username.text;
loginSuccessful = true;
//SEND DATA TO MAIN APPLICATION
dispatchEvent(new CustomEvent(CustomEvent.EVENT_TYPE_NAME, userID, loginSuccessful );
PopUpManager.removePopUp(this);
}else{
fail.visible=true;
username.text="";
password.text="";
username.setFocus();
}
}
protected function titlewindow1_removeHandler(event:FlexEvent):void
{
if (!loginSuccessful)
dispatchEvent(new CustomEvent(CustomEvent.EVENT_TYPE_NAME," userID, loginSuccessful ));
}
And in the Main Application::
import mycomponents.CustomEvent;
private function application1_creationCompleteHandler(event:FlexEvent):void
{
//...your code
login.addEventListener(CustomEvent.EVENT_TYPE_NAME, handleLoginEvent);
}
private function handleLoginEvent(aEvent:CustomEvent)
{
//My example code dispatches an event with mSuccess = false if the login prompt closes
//without a successful login
//
//now do whatever you want with the information from the popup
//aEvent.mUserID gets you ID
//aEvent.mSuccess gets you success
}
Tossed that together in the middle of a break at work, so no promises will compile as-is.