The NEXT thing to try!!

Icon

Random rants and tips about NETCF, WinCE, Emacs, Powershell etc.

Presenting Flex Analysis Services Bridge!!

In my last post, I gave an idea about how one can make their flex application talk to a Microsoft Analysis Services instance. Flex Analysis service Bridge and HTTP pump together provide a layer in between to enable communication between two.

Here is the high level diagram illustrating the design of the bridge and the workflow.Flex Analysis Services Bridge

Request:

  1. An XMLA request like DISCOVER_CUBES is sent to the XMLAService.
  2. XMLAService takes the request and uses it to create a SOAP request. The created SOAP request is then sent to the HTTP pump.
  3. HTTP pump (msmdpump.dll) then forwards the request to the Microsoft Analysis Services Instance.

Reply:

  1. Microsoft Analysis Services respond to the request and send the SOAP reply to the HTTP pump.
  2. HTTP pump then forwards the reply to the bridge.
  3. Bridge then parses the reply and create an actionscript representation of the reply. XMLAService then dispatches an XMLA_RESULT event which can be listened and appropriate action can be taken. After dispatching the event XMLAService also takes care of calling the responders if any registered.

Similarly, when cube.refresh() is called from the Flex application, the bridge starts reading the cube by sending SOAP requests to the HTTP pump which in turn forward these requests to the Microsoft Analysis Services instance. The ASCube keeps parsing the replies and building the cube. It also keeps sending CUBE_PROGRESS events. Once it receives all the replies, it dispatches a CUBE_COMPLETE event.

Same workflow is followed in case of query execution.

I also explained in detail the code you need to write in your flex application in my last post. You can see, after using the bridge it requires almost zero effort to connect with a remote OLAP cube. The implementation is generic enough and is supposed to work in case of a custom XMLA provider like mondrian. The only thing you need there is a serviceURL or in other words an equivalent of HTTP pump which can accepts POST requests. Feel free to use and drop in your feedback.

You can download the code here.

Filed under: actionscript, flex, flex component, OLAP

Using Flex™ 2.0.1 Language Reference offline

After playing with HTML Help Workshop for some time I have managed to compile the Flex™ 2.0.1 Language Reference in CHM format (CHM files are extensively used for documentation and help files).

This is similar to Help Window we get with the Flex Builder. FlexBuilder has a limitation that it doesnt allow using help unless FlexBuilder is open. This is where such a CHM is useful. It also has got search functionality and thus serves the purpose. Here are the steps to create a CHM file:

  1. Download Flex Language Reference from livedocs or alternatively take the zip from {Flex Builder installed location}/plugins/doc.zip (thanks to Sreenivas for pointing out this) and unzip it.
  2. Say the docs are located on PATH/flexapi.
  3. Download HTML Help Workshop from the following link and install it.
  4. Open HTML Help Workshop and go to File -> New and select Project. It will start a wizard.
  5. Give a name (say flex2.0.1_asdoc ), when asked for name of the project file.
  6. After clicking next, select HTML files checkbox (because we already have our doc created)
  7. In the next dialog box, press Add and give path of the index.html (PATH/flexapi/index.html)
  8. Click Finish to finish the wizard

Press Save to save the project and compile the project and click View Compile file button on the toolbar. You will find that the file created is broken because it has not included all the files. So we need to fix this. Actually HTML Help workshop has a limitation that it doesn’t pick files specified in CSS stylesheets and javascripts. Follow these steps to fix this:

  1. Close the project. And go to the project folder and open the .hhp file in any editor. You will find a [FILES] section in the file with index.html listed.
  2. Just do a find to find all the class-list.html files in the PATH/flexapi/ folder and add all those class-list files (with full path) after index.html
  3. Save this template.html file in the PATH/flexapi/ folder.
  4. Add template.html also to the list of [FILES] in .hhp file.

Now open the project again and re-compile the project. Use the CHM created when you are offline and not using FlexBuilder.

Here is a screenshot of CHM file I got. You can also take advantage of the search functionality and here is a screenshot for this.

Filed under: actionscript, flex

Using Autoinserting(emacs) for actionscript

This is my post second post in this series. After spending some time in lisp, I have managed auto-insert to work for actionscript.

Emacs has got Autoinserting which allows putting some predefined code in a file when you create it first time. This is a familiar concept for people who use IDEs like FlexBuilder for coding.

In flex builder when we create a class first time, it asks for the classname and other information like base class, interfaces and dump some code for the first time. Autoinserting is the answer to achieve such a functionality in emacs.

It works as follows:

  1. When you create a new file with .as extension, it prompts for the base class name
  2. Pressing ENTER will imply no base class otherwise it will insert the required code (import statement and extends string in the template)
  3. After that it asks for package name, again pressing ENTER will mean default (i.e top level package) otherwise package name given will be taken.
  4. It repeatedly keeps asking for the interfaces that you plan to implement, unless you press ENTER

Here is the required code you need to add to your .emacs file.

P.S :=> Don’t forget to set the flex-home variable

(auto-insert-mode t)
(setq auto-insert-alist
      (append '(((actionscript-mode .  "Actionscript Mode") . insert-as-template))
              auto-insert-alist))

(defvar flex-home "C:/flex/sdk/framework/src")

(defun get-dot-seperated (file-name)
  (interactive)
  (setq file-name (substring file-name 1 )) ;; Get rid of the first /
  (setq parts (split-string file-name "/")) ;; split string into parts based on /
  ;;Start creating . seperated import string
  (setq file-dot-path "")
  (while parts
    (setq token (car parts))
    (setq file-dot-path (concat   file-dot-path "." token))
    (setq parts (cdr parts)))
  (substring file-dot-path 1))

(defun insert-as-template ()
  (interactive)
  (let ((baseclass (read-file-name "[]base class?" flex-home))
        (package (read-string "[]Package?" ""))
        ;;(title (substring (file-name-nondirectory buffer-file-name) 0 -3))
        (title (file-name-sans-extension (file-name-nondirectory buffer-file-name)))
        (tab "t"))

    (insert (concat
             "package " package "n"
             "{n"))

    (setq hasBaseClass (not (or (= (length baseclass) 0)
                   (equal buffer-file-name baseclass))))

    (when hasBaseClass
      (setq foo (length flex-home))
      (setq base-class-name (substring baseclass foo ( - (length baseclass) 3))) ;;get /mx/controls/Datagrid from full path
      (insert (concat "import " (get-dot-seperated base-class-name) ";n")))

    (setq point-for-imports (point))

    (insert (concat "public class " title))

    (if hasBaseClass
        (insert (concat " extends " (file-name-sans-extension (file-name-nondirectory baseclass)))))

    (setq point-after-class (point))

    (insert (concat
             "n"
            "{n"
            "n"
            tab "//--------------------------------------------------------------------------n"
            tab "//n"
            tab "//  Constructorn"
            tab "//n"
            tab "//--------------------------------------------------------------------------n"
            "n"
            tab "/**n"
            tab "*  Constructor.n"
            tab "*/n"
            tab "public function " title "()n"
            tab "{n"
            tab tab "//Start from heren" tab tab))

   ;;bookmark this point, so that we can place the cursor here when finished
    (setq point-beginning (point))
    (insert (concat
            "n"
            tab "}n"
            "}n"
            "}n"
            )))

  (setq imports-for-interfaces "")
  (setq implements-string "")
  (setq base-class-path "")
  (setq prompt t)
  (while prompt
    (let ((interface (read-file-name "[]implements?" flex-home)))

      (when (not (or (= (length interface) 0)
                     (equal buffer-file-name interface)))

        (setq foo (length flex-home))
        (setq interface-name (substring interface foo ( - (length interface) 3))) ;;get /mx/controls/Datagrid from full path
        (setq imports-for-interfaces (concat imports-for-interfaces "import " (get-dot-seperated interface-name) ";n"))
        (setq implements-string (concat implements-string (file-name-sans-extension (file-name-nondirectory interface-name)) ",")))

      (if (or (= (length interface) 0)
              (equal buffer-file-name interface))
          (setq prompt nil))))

  (when (> (length implements-string) 0)
    (setq implements-string (substring implements-string 0 (1- (length implements-string))))
    (goto-char point-after-class)
    (insert (concat "nt" "implements " implements-string))
    (setq point-beginning (+ point-beginning (length implements-string))))

  (when (> (length imports-for-interfaces) 0)
    (goto-char point-for-imports)
    (insert (concat imports-for-interfaces "n"))
    (setq point-beginning (+ point-beginning (length imports-for-interfaces))))

  (goto-char point-beginning))

As a result I get this as my start file:

package src
{
import mx.controls.Tree;
import mx.controls.treeClasses.ITreeDataDescriptor;
import mx.collections.IViewCursor;

public class MyTree extends Tree
	implements ITreeDataDescriptor,IViewCursor
{

	//--------------------------------------------------------------------------
	//
	//  Constructor
	//
	//--------------------------------------------------------------------------

	/**
	*  Constructor.
	*/
	public function MyTree()
	{
		//Start from here

	}
}
}

Filed under: actionscript, emacs

Using Imenu (emacs) for actionscript

If you use emacs as your editor while programming in actionscript, then this tweak could be really useful for you.

Emacs has got Imenu facility which allows finding major definitions in a file/buffer. In the context of actionscript this includes class definitions, private/protected/public variables, getters/setters and ofcourse functions. Thus, using Imenu you can bind your keys so that it jump on the definition of a function when those keys are pressed. When you change the contents of the file, you can press

*Rescan*

to make it re-read the buffer and generate a new indexing of the file contents. You can also set

'imenu-auto-rescan'

to a non-nil value so that it automatically scans your file, everytime you make any changes. Here is screenshot of the Imenu:

actionscript-mode is already available for emacs and thus by using the mode you can get all sort of code-coloring. After adding actionscript-mode to your mode-list, you need to add this code to your .emacs to get the desired functionality.


(add-hook 'actionscript-mode-hook 'imenu-add-menubar-index)
(add-hook 'actionscript-mode-hook 'actionscript-init-imenu)
(defun actionscript-init-imenu ()
  (interactive)
  (setq imenu-generic-expression as-imenu-as-generic-expression)
  (global-set-key [mouse-3] 'imenu))(defvar as-imenu-as-generic-expression
  ` (
    ("variables"
     ,(concat
       "^"
        "[ t]*(public|protected|mx_internal|private)"
        "[ t]+var"
        "[ t]+([a-zA-Z_][a-zA-Z0-9_]*)"     ; match function name
        "[ t]*:([a-zA-Z_][a-zA-Z0-9_]*)"        ), 2)

    ;; Getters
    ("Getters"
     ,(concat
       "^"
       "[ t]*(override[ tn]+)?"
        "[ t]*(public|protected|mx_internal|private)"
        "[ t]+function"
        "[ t]+"
        "(get[ t]+([a-zA-Z_][a-zA-Z0-9_]*)[ t]*)()"
       ) 3)

    ;;setters
    ("setters"
     ,(concat
       "^"
       "[ t]*(override[ tn]+)?"
        "[ t]*(public|protected|mx_internal|private)"
        "[ t]+function"
        "[ t]+"
        "(set[ t]+([a-zA-Z_][a-zA-Z0-9_]*)[ t]*)"
        "("
        "([a-zA-Z_][a-zA-Z0-9_]*):([a-zA-Z_][a-zA-Z0-9_]*)[ tn]*"
        ")"
       ) 3)

;; Class definitions
    (nil
     ,(concat
         "^"
         "((public|protected|mx_internal|private)[ t]+)?"
         "(class|interface)[ t]+"
         "("                                ; the string we want to get
         "[a-zA-Z0-9_]+"                      ; class name
         ")"
         "[ tn]*"
         "(extends [ tn]*[a-zA-Z0-9_]+)?"
         "[ tn]*";;[:{]"
         "(implements [ tn]*([a-zA-Z0-9_]+[,][ tn]*)*[a-zA-Z0-9_])?"
         "[ tn]*";;[:{]"
         ) 4)

;; General function name regexp
    (nil
     ,(concat
       "^"
       "[ t]*(override[ tn]+)?"
        "[ t]*(public|protected|mx_internal|private)"
       "([ t]+static)?"
        "[ t]+function"
        "[ t]+([a-zA-Z_][a-zA-Z0-9_]*)"     ; match function name
        "[ t]*("
        "[^)]*)"
       ) 4)
    )
  "Imenu generic expression for C++ mode.  See `imenu-generic-expression'.")

Attached is my .emacs file

Filed under: actionscript, emacs

Performance Tuning in ActionSctipt 3.0

Yesterday I went through this nice document by Gray Grossman (creator of ActionScript) which talks about some easy tips and tricks to boost the runtime performance of your code. Too my surprise I was not following any of the three tips he has mentioned.

Promotoion of Numeric types – An array in Actionscript is nothing but a hash so an access to any element in the array is used as a key to find the value. This happens everytime you write something like array[f]. But in AS an array access is faster if the key is a int/uint. To take advantage of this one can just force the access to be index based rather then key based by type coercion of the index. This can be done by accessing the value as array[(int(f)]. Isn’t this a cool, neat and nice way?

Common Subexpression Elimination – Common Subexpression elimination is compiler optimization techinique which is employed by almost all the matured compilers. What they do is they cache some of frequently occuring common subexpressions and provide the result from the cached values but sometimes the language semantics do not allow compiler to deploy this optimization while generating code. As rightly pointed out by the author because in actionscript we have concept of getters and setters a getter/setter subexpression cannot be eliminated.Let’s say you have a property p in your AS class C and you have defined getters/setters for the property like this:

public function get p():*
{
return _p;
}


public function set p(value:*):void
{
_p = value;
pDirty = true
}

In the code if you access this property using the getter the compiler is bound not to eliminate the subexpression. But if you are using _p you are safe.

One more such example is of array.length

for (var i:int=0; i<array.length; i++)
{

}

Here also compiler can’t eliminate a.length and thus it is advisable to use:

var n:int = array.length
for (var i:int=0; i<n; i++)
{

}

Method Closures– AS is based on ECMAScript specification and thus it allows nested functions. An example could be:

public function f()
{
var g:Function = (function (args:Array)
{
trace(“I am in g”);
});

But having a nested function costs. For each nested function, the outer function has to create an activation object which has some performance and memory impact.
Now what are these memory impacts? Whenever a function is executed a activation object is created for the call. In lay man terms it is actually pushing all the arguments, the return address on the stack. Thus an activation object stores all these things along with all the local variable declarations. Along with this a scope chain is also created that contains an ordered list of objects that Flash Player checks for identifier declarations. Thus each function has a scope chain property (internal property) associated with it. The scope chain goes up until it reaches the global object.

Coming back to nested functions, in case of such declarations not only there is an overhead of an extra storage for activation object, the increase in length of the scope chain increases the scope of the function and thus player’s job of scope-resolution increases which hurts performance.

Thus, next time your code execution can become really slow if you just don’t bother!!!

Filed under: actionscript

Flexing easily: Flex module

Recently there was an interesting announcement on flex team blog about the release of Flex Module for Apache and IIS.

It provides web-tier compilation of mxml and Actionscript files on Apache and IIS server. This will enable developers to run their code like server-side scripting languages (PHP, ColdFusion etc.) i.e just code you application say myApp.mxml and run it through browser through its url (http://www.flex.com/myApp.mxml).

To give an idea about how helpful this could be just think what before this a developer needs to do test their application. Developer builds his application in some editor (for me emacs :P), compiles it and the open the created swf in the browser (with or without a wrapper HTML). But with this flex module the intermediate steps of compiling the application and opening in the browser can be skipped and the module will itself do this for him.

Moreover, downloading source codes of sample applications and trying them out is also will be easier. For people using Flex Builder, it’s always a pain to import a third party source code in your project and configuring it according to your needs. Now, you can just download the source code and copy it on your web server and see the results (No flex builder coming in between). A step further its very easy to make changes to those source codes using any editor and directly see them in the browser.

One more thing which I liked about Flex module is the nice way of showing errors (if there are any in your applications).

1 error found
C:\www\webroot\samples\explorer\explorer.mxml:47

ERROR : Parse error at ”.

46  
47 <mx:HTTPService id=”charts” url=”charts_explorer.xml” resultFormat=”e4x” result=”chartsLoaded();” fault=”populateTree()” />
48  

If I compare it with some server-side scripting languages like PHP, this is great. In PHP, because it is a scripting language it becomes difficult to catch errors and sometimes it shows blank screen signifying an error in the script and thus if becoms difficult to find out what part is causing error. I am sure there might be tools available for PHP which can overcome this shortcoming of PHP which I am not aware of.

If you are interested in learning more about Flex Module, Ryan Stewart has explained it very well in his blog.

For installing Flex module it asks about following things:

  1. Your SDK directory path.
  2. Your Web Server root path (For me Apache).
  3. Your webroot path.
  4. Location of the compiler cache folder

Filed under: actionscript, flex, Internet Tools

Buzz in the Cerulean studio about Apollo

clipped from blog.ceruleanstudios.com

Apollo
trillianastra-apollo.png

  powered by clipmarks blog it

Apollo public alpha is live now. Apollo enables web developers to use their (Flash, Flex and HTML) skills for developing desktop applications which could be run on Apollo. Apollo provides cross-operating system runtime to these applications.

I have been using trillian since last 4 yrs and its good to see some good people developing applications on top of apollo.

Filed under: actionscript

actionscript-mode for emacs!!!

I have been working on actionscript for more than 8 months. And had’t heard about any mode available for actionscript so far. But recently I found one. Emacs is my weakness and without emacs I really feel weak.

But thankfully now someone has written an actionscript-mode for emacs also. The workaround was to use javascript-mode or java-mode. But it somehow doesn’t give you that good feeling. Though I have yet to discover all the good offerings this mode has. But in case you are interested you can find the mode here.

And to add to it this mode supports AS3. So what are you waiting for?

Filed under: actionscript, emacs

About the author

avatar
25, Male, living in Hyderabad Mobile Developer, working for Microsoft IDC

View Nisheet Jain's profile on LinkedIn

RSS Mobile Dev Blog

  • An error has occurred; the feed is probably down. Try again later.