How to capture user credentials provide in flash swf file in flex?

How to capture user credentials of flash swf file in flex?

Here i am attaching snippet and swf files for your reference.

Regards,
Naveen.
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" height="100%" width="100%">

<mx:SWFLoader id="loader1" source="assests/sampark_HR.swf" y="0" width="1300" height="1200" x="0"/>
<mx:SWFLoader id="loader2" source="assests/sampark_bottom.swf" y="490" width="1300" height="1200" x="0"/>
	
</mx:Application>

Open in new window

sampark-HR.swf
sampark-bottom.swf
naveenm_006Asked:
Who is Participating?
 
deepanjandasConnect With a Mentor Commented:
Try this:
public function doLogin( event:MouseEvent ):void
{                                
          var username:String = loadedSM.application["userTextFieldInstanceName"].text;
          var password:String = loadedSM.application["passTextFieldInstanceName"].text;

          if(isBlank(username)){
               Alert.show('username can not be empty');
          }
          if(isBlank(password)){
               Alert.show('password can not be empty');
          }                                
     //}
}


function isBlank(value:String):Boolean
{
    var tmpArray:Array = value.split(" ");

    if (tmpArray.length <=0 )
        return true;
    var count:int = 0;

    for (var i:int = 0; i < tmpArray.length; i++){
        if (tmpArray[i].length <= 0 )
        count++;
    }

    if (count == tmpArray.length)
        return true;
    return false;
}

Open in new window


Warm Regards
Deepanjan Das
0
 
deepanjandasCommented:
This link might be helpful, use SystemManager:
http://help.adobe.com/en_US/flex/using/WS2db454920e96a9e51e63e3d11c0bf69084-7f9c.html

Warm Regards
Deepanjan Das
0
 
naveenm_006Author Commented:
Can you provide me some sample snippet for this. I looked into the link which you have provided but i didn't get any thing regarding my query.

Anyway i am sharing one swf file for your reference which is the first page of my application(hrhelpdesk).

Regards,
Naveen.
main.swf
0
Free tool for managing users' photos in Office 365

Easily upload multiple users’ photos to Office 365. Manage them with an intuitive GUI and use handy built-in cropping and resizing options. Link photos with users based on Azure AD attributes. Free tool!

 
naveenm_006Author Commented:
0
 
deepanjandasCommented:
Try this:
 
<?xml version="1.0"?>
<!-- controls\swfloader\SWFLoaderInteract.mxml -->
<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"
    backgroundColor="gray"
    height="200">

    <fx:Script>
        <![CDATA[
            import mx.managers.SystemManager;
            
            [Bindable]
            public var loadedSM:SystemManager;

            // Initialize variables with information from
            // the loaded application.
            private function initNestedAppProps():void {
                loadedSM = SystemManager(myLoader.content);
                loadedSM.application["loginButtonInstanceName"].addEventListener( MouseEvent.CLICK, doLogin, false, 0, true );
            }
            public function doLogin( event:MouseEvent ):void {
                //"userTextFieldInstanceName" is the username text field instance name 
                var username:String = loadedSM.application["userTextFieldInstanceName"].text;
                var password:String = loadedSM.application["passTextFieldInstanceName"].text;
                //now call your request with the username and password parameter in flex to validate login credentials
            }
        ]]>
    </fx:Script>
    <s:VGroup> 
        <s:Label id="lbl"/>
        <mx:SWFLoader id="myLoader" width="300"
            source="assests/sampark_bottom.swf"
            complete="initNestedAppProps();"/>
      
    </s:VGroup>
</s:Application>

Open in new window



Warm Regards
Deepanjan Das
0
 
naveenm_006Author Commented:
When i run/debug your application i am getting the following error:

TypeError: Error #1034: Type Coercion failed: cannot convert flash.display::AVM1Movie@5213e81 to mx.managers.SystemManager.
      at main/initNestedAppProps()[D:\naveen.kumar\Documents\Flex Builder 3\hrhelpdesk\src\main.mxml:17]
      at main/__myLoader_complete()[D:\naveen.kumar\Documents\Flex Builder 3\hrhelpdesk\src\main.mxml:34]
      at flash.events::EventDispatcher/dispatchEventFunction()
      at flash.events::EventDispatcher/dispatchEvent()
      at mx.core::UIComponent/dispatchEvent()[C:\autobuild\3.5.0\frameworks\projects\framework\src\mx\core\UIComponent.as:9440]
      at mx.controls::SWFLoader/http://www.adobe.com/2006/flex/mx/internal::contentLoaderInfo_completeEventHandler()[C:\autobuild\3.5.0\frameworks\projects\framework\src\mx\controls\SWFLoader.as:2064]
0
 
deepanjandasCommented:
The swfs that you are using are in AS2.
I though those were in AS3.0.

Then you have to use FlashInterface or ExternalInterface.

Warm Regards
Deepanjan Das
0
 
naveenm_006Author Commented:
ok thanks for your reply,

may i know what this piece of code tells

complete="initNestedAppProps();"

when it is going to invoke.

Regards,
Naveen.
0
 
naveenm_006Author Commented:
which swf file you are saying to convert as3.There are two swf files.
1)sampark_HR.swf
2)sampark_bottom.swf

Both i need to convert or only one.If one which swf file need to convert from as2 to as3.

Regards,
Naveen.
0
 
deepanjandasCommented:
Basically which ever files you want to communicate with flex must be AS3.0 if you want to avoid using FlashInterface and making it more complex.

Here sampark_bottom.swf is going to communicate with Flex, so if possible convert it tro AS3.0

This
complete="initNestedAppProps();"
means that on loading complete of the swf the function initNestedAppProps() will get called which have been defined above.
You can change the name of the function.

Warm Regards
Deepanjan Das
0
 
naveenm_006Author Commented:
What are these below instances which you are used in the code? These are the instance names used in as3.0 am i right?

loginButtonInstanceName
userTextFieldInstanceName
passTextFieldInstanceName

Regards,
Naveen.
0
 
deepanjandasCommented:
yes, exactly :).
The instance names used in the flash.
For e.g.
loginButtonInstanceName is the name of the login button.

Warm Regards
Depanjan Das
0
 
naveenm_006Author Commented:
Hi now i am getting the following error after converting as2 to as3

TypeError: Error #1034: Type Coercion failed: cannot convert sampark_bottom_fla::MainTimeline@7a0cf89 to mx.managers.SystemManager.
      at main/initNestedAppProps()[D:\naveen.kumar\Documents\Flex Builder 3\hrhelpdesk\src\main.mxml:15]
      at main/__myLoader_complete()[D:\naveen.kumar\Documents\Flex Builder 3\hrhelpdesk\src\main.mxml:30]
      at flash.events::EventDispatcher/dispatchEventFunction()
      at flash.events::EventDispatcher/dispatchEvent()
      at mx.core::UIComponent/dispatchEvent()[C:\autobuild\3.5.0\frameworks\projects\framework\src\mx\core\UIComponent.as:9440]
      at mx.controls::SWFLoader/http://www.adobe.com/2006/flex/mx/internal::contentLoaderInfo_completeEventHandler()[C:\autobuild\3.5.0\frameworks\projects\framework\src\mx\controls\SWFLoader.as:2064]

Plz find the attachements.

Regards,
Naveen.

<?xml version="1.0" encoding="utf-8"?>
<!-- controls\swfloader\SWFLoaderInteract.mxml -->
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" backgroundColor="gray">

    <mx:Script>
        <![CDATA[
            import mx.managers.SystemManager;
           
            [Bindable]
            public var loadedSM:SystemManager;

            // Initialize variables with information from
            // the loaded application.
             private function initNestedAppProps():void {
                loadedSM = SystemManager(myLoader.content);
                loadedSM.application["loginButtonInstanceName"].addEventListener( MouseEvent.CLICK, doLogin, false, 0, true );
            } 
            public function doLogin( event:MouseEvent ):void {
                //"userTextFieldInstanceName" is the username text field instance name 
                var username:String = loadedSM.application["userTextFieldInstanceName"].text;
                var password:String = loadedSM.application["passTextFieldInstanceName"].text;
                trace(username);
                trace(password);
                //now call your request with the username and password parameter in flex to validate login credentials
            }
        ]]>
    </mx:Script>
      
        <mx:SWFLoader id="loader1" source="assests/sampark_HR.swf" width="1300" height="1200"/>
        <mx:SWFLoader id="myLoader" source="assests/sampark_bottom.swf" y="482" width="1300" height="1200" x="0" complete="initNestedAppProps();"/>
             
</mx:Application>

Open in new window

sampark-bottom.fla
sampark-bottom.swf
0
 
naveenm_006Author Commented:
anyway i got successful output.But now the problem is how to do client side validations like if username and password not entered it should show some alert message saying username/password can not be empty.

How can we get this functionality.

Here i am sharing the code what i have made changes to that code.

Regards,
Naveen.
loadedSM = myLoader.content;
loadedSM.addEventListener( MouseEvent.CLICK, doLogin, false, 0, true );

Open in new window

0
 
deepanjandasCommented:
in doLogin() method check for blank values and show an alert in flex itself.

Warm Regards
Deepanjan Das
0
 
naveenm_006Author Commented:
can you provide me sample code.I have tried like this:

                             public function doLogin( event:MouseEvent ):void
                       {                                
                               //"userTextFieldInstanceName" is the username text field instance name
                               if(event.target.name == "loginButtonInstanceName"){
                               var username:String = loadedSM.userTextFieldInstanceName.text;
                               var password:String = loadedSM.passTextFieldInstanceName.text;
                               trace(username);
                               trace(password);
                              if(username.length<0)
                               {
                                     Alert.show('username can not be empty');
                               }
                               if(password.length<0){
                                     Alert.show('password can not be empty');
                               }
                               
                               }
                         }
am i doing the correct?
0
 
naveenm_006Author Commented:
Need to focus input textfield by default when the application launches so that user no need to manual point the cursor into the input textfield. This functionality i need how can we do this?
0
All Courses

From novice to tech pro — start learning today.