Monday, November 27, 2006

Introduction to Flex Data Services 2

Introduction to Flex Data Services 2
11/28/2006
2:00 PM US/Eastern

http://www.adobe.com/cfusion/event/index.cfm?event=track&id=539086&loc=en_us

Tuesday, November 14, 2006

Calling web services in ActionScript


Calling web services in ActionScript


private function initMe(e:Event):void {

con.useProxy = false ;
con.wsdl = http://localhost/TestService.asmx?wsdl;
if (con.canLoadWSDL()){
con.loadWSDL();
}

con.login.addEventListener("result", loginResultHandler);
con.addEventListener("fault", wsFaultHandler);

}

private function loginClickHandler (event : Event ){

con.login(t1.text , t2.text );
}

private function wsFaultHandler (fault : Object ){

Alert.show(""+fault.faultString);
}

Tuesday, October 31, 2006

Sending custom class object thru remoting using OpenAmf

Passing UDT from java to flex using openAmf based remoting.

Finally the battle is over. Was in lot of pain pasing a
custom object as response to remote call to java. 2 man days
wasted.

Java (server side) :

Remote Class (UDT): TestClass.java

package com.vishwajit.test.BO;

import java.io.Serializable;

public class TestClass implements Serializable {

private String testValue ;

public TestClass() {
}

public String getTestValue() {
return testValue;
}

public void setTestValue(String testValue) {
this.testValue = testValue;
}
}

Remote Method : (Inside Service.java)

public static TestClass Test()
{
TestClass obj = new TestClass();
obj.setTestValue("setyblch");
return obj;
}

Open AMF Mapping

(if you have not already set this one...)
<amf-serializer>

 <force-lower-case-keys>false</force-lower-case-keys>

</amf-serializer>

      


<custom-class-mapping>>

 <java-class>com.vishwajit.test.BO.TestClass</java-class>

 <custom-class>vishwajit.TestClass</custom-class>

</custom-class-mapping>



Client Side (flex / swf):

public function TestHandler (obj : Object ):void {

var testObj:TestClass = TestClass(obj);
Alert.show("" + testObj.testValue );
}

Wednesday, October 25, 2006

Problem invoking any webservice operation if the API contains a method called 'logout'

Figured out a weird issue with Flex 2.0 / Flash Player 9 . Your comments welcome.


Issue:
When you are calling any webservice where the API contains a method/function/operation named 'logout' your call wont be processed.
and you get the exception mentioned in trace .

Just to confirm the issue I tried writing webservice in Intersystems Cache and .NET 1.0 .
The issue lies with webmethod name 'logout' , if its renamed to something else the life is good.

Trace :
TypeError: Error #1034: Type Coercion failed: cannot convert MC{mx.rpc.soap.mxml::WebService@1393c41 mx.rpc::AbstractService/logout()}@132a7b9 to mx.rpc.soap.Operation.

Tuesday, October 17, 2006

Webservice Result for Flex 2

Getting result of Webservice.

Result is available in the operation object property lastResult.

Sample
Alert.show(loginWS.login.lastResult + "");

Crossdomin access for webservice

1 Invoking webservice in Flex without FDS
2 Solution for MessaginError message='Unknown destination'DefaultHTTP'.'

1
If You are not using FDS
On the Webserice Object
set 'proxy' = false
do not set the 'destination' property instead
set 'wsdl' to the path of wsdl

2 Use crossdomin.xml file on the server that is hosting the webservice. This file should grant access to clients domain. Place this file at the root of the webserver.

example

<?xml version="1.0"?>

<!DOCTYPE cross-domain-policy SYSTEM "http://www.macromedia.com/xml/dtds/cross-domain-policy.dtd">

<cross-domain-policy>

   <allow-access-from domain="*" />

</cross-domain-policy>





Any other queries : Post comment.

Calling a webservice in Flex 2

Making a webservice call in Action Script 3.0
Without using FDS

Flex webservice Sample.

<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
layout="absolute" creationComplete="creationCompleteHandler()" >

 <mx:WebService id="loginWS"

 

 wsdl="http://vishwajit/TestWS/Service1.asmx?WSDL"

  

 useProxy="false" 

 fault="wsFault(event)" >

 

 <mx:operation name="HelloWorld" result="HelloWorldResult(event)" 
>   


  </mx:operation>

 

 <mx:operation name="login" result="getLoginResult(event)"  >

    <mx:request xmlns="" >  

    <loginId>a1</loginId>

    <password>a1</password> 

   </mx:request>

  </mx:operation>

 </mx:WebService>

 

 

 <mx:Script>

  <![CDATA[

  import mx.controls.Alert;

  

  public function creationCompleteHandler()

  {

  

  

  loginWS.login.send();  

  //loginWS.HelloWorld.send();

 

  }

   

   

  public function HelloWorldResult(result : Object)

  {

   Alert.show("HelloWorldResult");

  }

   

   



  public function wsFault(fault:Object)

  {

   Alert.show(""+fault);

  }

   

  ]]>

 </mx:Script>

</mx:Application>




Time wasted/invested on the issue 2.5 Man days

Friday, September 29, 2006

Programatically adding appender to Log4j

Wanted to use Log4j without configuration file.
So here is the clean code.

//Java

FileAppender fa = new FileAppender(new SimpleLayout(),filename,true);


fa.activateOptions();
Logger logger = Logger.getLogger(filename);
logger.addAppender(fa);
logger.info(data);
logger.removeAllAppenders();

Thursday, September 28, 2006

SWFLoader : Dynamically load / unload my 'sub applications' in Flex 2.0

Dynamically load / unload my 'sub applications' in Flex 2.0 (compiled swf) but user feel should be as if only one mxml has been loaded.

One problem in flex...

You have 3 .mxmls that get compiled into .swf ( Say A , B , C . )

step1 You have to load B inside A
step2 In B there is a button on click you have to unload B from A and load C
step3 Also in C there is a button on click you have to unload C from A and load B

---

My approach

for Step1 : cool!
I am loading B in A using SWFLoader.

for step2 : stuck!
I am not able get hold of the instance A from which i can change source property of swfLoader (instance) to "C.swf"

for step : whatever works for step 2 :-(


--
Solution ;)

Two days after making this post I figured out a simple way to achieve this.
Code below demonstrates the my approach.

Thanks,
Vishwajit Girdhari
Flexblog : http://flexiness.blogspot.com

Main.mxml

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

<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
layout="absolute"

creationComplete="init(event)" >


 <mx:Script>

  <![CDATA[   

   import mx.controls.Alert;

         import flash.events.Event;

         private function init(e:Event):void
{

          //doing nothing

           }

   public function loadSWF (filename : String) : void
{       

          swfLoader.source=filename;

         }    


       ]]>

 </mx:Script> 


   <mx:SWFLoader id="swfLoader"  source="one.swf"  
></mx:SWFLoader>

</mx:Application>

 

one.mxml

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

<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
layout="absolute">

<mx:Script>

 <![CDATA[

  import mx.controls.Alert;

  public function handleOne ( event : Event ) :void {

      mx.core.Application.application.loadSWF("two.swf");     
 

  }

   

 ]]>

</mx:Script>

<mx:Button id="btnOne" label="Button One" click="{handleOne(event)}"
y="200"></mx:Button> 

</mx:Application>

 

two.mxml

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

<mx:Application xmlns:mx="
http://www.adobe.com/2006/mxml"
layout="absolute">

<mx:Script>

 <![CDATA[

  import flash.profiler.showRedrawRegions;

  import mx.controls.Alert;

  

  public function handleTwo ( event : Event ) :void {

   mx.core.Application.application.loadSWF("one.swf");     
 

  }

 ]]>

</mx:Script><mx:Button id="btnTwo" label="Button Two"
click="handleTwo(event)" x="300"></mx:Button> 

</mx:Application>



Friday, September 08, 2006

Printing a hash map in flex

A small piece of AS code that saves a lot of my debug time and frustrations...

Mostly use while understanding the remote object structure.

//code:
//Alerting the hashmap contents

var str = "";
for(var k:String in hashMap)
{
str += k + ":" + hashMap[k] + "\n";
}
Alert.show("Printing hash map : \n" + str);

Monday, March 20, 2006

Tomcat 5.5 admin package.

Tomcat 5.5 admin package.

Tomcat's administration web application is no longer installed by default. Download and install the "admin" package to use it.

http://apache.tradebit.com/pub/tomcat/tomcat-5/v5.5.16/bin/apache-tomcat-5.5.16-admin.zip

Tuesday, March 14, 2006

Implementing double click in flex

Application to demonstrate a possible implementation ' double click ' in Flex v 1.5


DoubleClickDemo.mxml

 


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

<!--

/////////////////////////////////////////////////////////////////////////////////////////

// Application to demonstrate a possible implementation ' double click '
in Flex v 1.5 

// Author   : Vishwajit Girdhari               

// Date   : 14-Mar-2006

// Flex Blog  : http://flexiness.blogspot.com

// Blog  : http://vishwajit.blogspot.com

// Website  : www.vishwajit.com

// email   : vishwajit @ gmail.com

/////////////////////////////////////////////////////////////////////////////////////////

-->

<mx:Application xmlns:mx="http://www.macromedia.com/2003/mxml">

  <mx:Script source="DoubleClickDemo_script.as" >

  </mx:Script>

  <mx:Panel>

    <mx:Button   id ="btnTest" label="Test single /
double click"  click="button_clicked()"  ></mx:Button>

  </mx:Panel>

</mx:Application>



DoubleClickDemo_script.as

/////////////////////////////////////////////////////////////////////////////////////////
// Application to demonstrate a possible implementation ' double click ' in Flex v 1.5
// Author : Vishwajit Girdhari
// Date : 14-Mar-2006
// Flex Blog : http://flexiness.blogspot.com
// Website : www.vishwajit.com
// email : vishwajit @ gmail.com
/////////////////////////////////////////////////////////////////////////////////////////

//Define the time duration to identify a double click.
var duration = 300;
var timer ;

//Called when the mouse button is clicked
function button_clicked()
{
// double click happened
if(timer != null)
{
// Call a specialised event for double click here.
mx.controls.Alert.show("Double click!");


//clean up
clearInterval(timer);
timer = null;
}
else
{
//start timer on first click
// setInterval obj,callback function,time interval
timer = setInterval(this,"click",duration);
}
}


// handles single clicks
function click(){

// Call a specialised event for single click here.
mx.controls.Alert.show("Single click!");

//clean up
clearInterval(timer);
timer = null;
}

Windows like behaviour for a panel in flex

I wanted to create a panel that could be be minimized, maximized, moved like a typical 'window'.This article helped me achiving this.
http://www.coenraets.com/viewarticle.jsp?articleId=89

Saturday, March 11, 2006

Flexiness

Whats is flexiness ?

I don't know ............simple.

Got chance to work on Macromedia (now Adobe) Flex and that had impact on the way I have been looking at UI. ASP.NET started feeling like pain. Regular websites started looking to thin and dull. Started to feel the power of RIA and the possibilties limited only by your imagination.

I got hooked. My UI changed as well ....... got a few tshirts....... Osho chappals...... whatever appealed to designer in me. Not limited by external voices.......

still looking for more stuff ......

This my flexiness ............to be able to adapt to anything (presently ...technology) under the sun.

-Vishwajit