Solved

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

Posted on 2011-02-16
17
1,244 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 10
  • 7
17 Comments
 
LVL 17

Expert Comment

by:deepanjandas
ID: 34913575
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
ID: 34913619
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
Simple, centralized multimedia control

Watch and learn to see how ATEN provided an easy and effective way for three jointly-owned pubs to control the 60 televisions located across their three venues utilizing the ATEN Control System, Modular Matrix Switch and HDBaseT extenders.

 
LVL 17

Expert Comment

by:deepanjandas
ID: 34913739
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
ID: 34913818
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
ID: 34913961
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
ID: 34914186
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
ID: 34914340
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
 
LVL 17

Expert Comment

by:deepanjandas
ID: 34914430
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
ID: 34914509
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
ID: 34914755
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
ID: 34923249
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
ID: 34924022
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
ID: 34924107
in doLogin() method check for blank values and show an alert in flex itself.

Warm Regards
Deepanjan Das
0
 

Author Comment

by:naveenm_006
ID: 34924402
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
ID: 34924455
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
ID: 35041776
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

Put Machine Learning to Work--Protect Your Clients

Machine learning means Smarter Cybersecurity™ Solutions.
As technology continues to advance, managing and analyzing massive data sets just can’t be accomplished by humans alone. It requires huge amounts of memory and storage, as well as high-speed processing of the cloud.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

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…
First of all let me say that the only language that I speak is English, but in answering questions here I often come across people whose English skills are not the best and I’d like to be able to communicate better with them, and the following descr…
In this video, viewers will be given step by step instructions on adjusting mouse, pointer and cursor visibility in Microsoft Windows 10. The video seeks to educate those who are struggling with the new Windows 10 Graphical User Interface. Change Cu…
Michael from AdRem Software outlines event notifications and Automatic Corrective Actions in network monitoring. Automatic Corrective Actions are scripts, which can automatically run upon discovery of a certain undesirable condition in your network.…

617 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