Solved

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

Posted on 2011-02-16
17
1,210 Views
Last Modified: 2012-06-21
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
0
Comment
Question by:naveenm_006
  • 10
  • 7
17 Comments
 
LVL 17

Expert Comment

by:deepanjandas
Comment Utility
This link might be helpful, use SystemManager:
http://help.adobe.com/en_US/flex/using/WS2db454920e96a9e51e63e3d11c0bf69084-7f9c.html

Warm Regards
Deepanjan Das
0
 

Author Comment

by:naveenm_006
Comment Utility
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
 

Author Comment

by:naveenm_006
Comment Utility
0
 
LVL 17

Expert Comment

by:deepanjandas
Comment Utility
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
 

Author Comment

by:naveenm_006
Comment Utility
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
 
LVL 17

Expert Comment

by:deepanjandas
Comment Utility
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
 

Author Comment

by:naveenm_006
Comment Utility
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
 

Author Comment

by:naveenm_006
Comment Utility
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
What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

 
LVL 17

Expert Comment

by:deepanjandas
Comment Utility
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
 

Author Comment

by:naveenm_006
Comment Utility
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
 
LVL 17

Expert Comment

by:deepanjandas
Comment Utility
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
 

Author Comment

by:naveenm_006
Comment Utility
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
 

Author Comment

by:naveenm_006
Comment Utility
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
 
LVL 17

Expert Comment

by:deepanjandas
Comment Utility
in doLogin() method check for blank values and show an alert in flex itself.

Warm Regards
Deepanjan Das
0
 

Author Comment

by:naveenm_006
Comment Utility
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
 
LVL 17

Accepted Solution

by:
deepanjandas earned 500 total points
Comment Utility
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
 

Author Closing Comment

by:naveenm_006
Comment Utility
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

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Flex 3 and Flex 4 Wasi Dashboard modify graphs in Pod.mxl datasource 3 417
Adobe AIR in bar  launch 3 262
Port 4000 issue 1 1,889
AS 3 - Movie editor 7 474
First things first - Preparation We need all the part for this install and it's much nicer to have them all on hand when you need them so here's what's required. Download Eclipse 3.5 32 bit (I like the Classic flavour) from here. (http://www.e…
In this step by step tutorial with screenshots, we will show you HOW TO: Enable SSH Remote Access on a VMware vSphere Hypervisor 6.5 (ESXi 6.5). This is important if you need to enable SSH remote access for additional troubleshooting of the ESXi hos…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

771 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now