Tuesday 29 March 2011

flex, how to print from flash / flex application...

problem:
Print is important from some applications, for any kind of receipt. Imagine that you may use resources from internet server to issue a doc at client's terminal where has nothing except a printer... i.e. tickets!

solution:
Flex supports a very easy way to print... just create a Group container (or a display container in general) and pass in addPage method...
The follow example prints itself (as I pass the this as argument to addPage method).

            internal function print():void{
                var printJob:PrintJob = new PrintJob();
                if (printJob.start()){      //this open's the dialog
                    printJob.start();       //if user choose 'print' then... start
                    printJob.addPage(this);
                    printJob.send();
                }
            }


Read the help about the PrintJob object where is not complex and it is tiny.

disadvantages:
The user has to press the print button in the system's print dialog box.
You cannot adjust the page size.

Wednesday 23 March 2011

adobe flex how to pass parameters arguments from html to swf flex / flash application

problem:

how to inform an swf with some arguments / parameters with values

solution:

the solution is similar how you call an php code

Passing arguments from URL query (http://www.mycompany.com....)
http://www.mycompany.com/movie.swf?firstVar=101ps

Passing arguments from HTML code
Assuming the image filename is image1.jpg, located at a folder named images.  And assuming that the Flash movie will use a variable named imageFilename to refer to the file, then we can do this:

<OBJECT classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"
  codebase="http://download.macromedia.com/"  
  WIDTH="250" HEIGHT="300" id="flaMovie1">
  <PARAM NAME=movie VALUE="flaMovie1.swf?imageFilename=images%2Fimage1%2Ejpg">
  <PARAM NAME=quality VALUE=high>
  <PARAM NAME=bgcolor VALUE=#FFFFFF>
  <EMBED src="flaMovie1.swf?imageFilename=images%2Fimage1%2Ejpg"
    quality=high bgcolor=#FFFFFF WIDTH="250" HEIGHT="250" NAME="flaMovie1"
    TYPE="application/x-shockwave-flash"
    PLUGINSPAGE="http://www.macromedia.com/go/getflashplayer">
  </EMBED>
</OBJECT>


There you see that I appended a query string after the Flash movie filename (flaMovie1.swf).  The query string contains one variable: imageFilename, with the value of images/image1.jpg.  
Note: The %2F is the url encoding for the "/" sign, and %2E is the url encoding for the "." sign.  Since these symbols are unsafe or reserved, we should url encode them, although at the present Flash does not seem to care.  So saying: imageFilename=images%2Fimage1%2Ejpg is essentially the same as saying imageFilename=images/image1.jpg (see: Introduction to URL Encoding)

Reading arguments in Flex from HTML
root.loaderInfo.parameters.firstVar
root.loaderInfo.parameters.ImageFilename
The "parameters" is an array with the arguments. The "firstVar" in Flex code is not a known variable but it is supported from Array or Flex.

Wednesday 16 March 2011

how to hide (for some reason) an application(s) from your computer

problem:
in some cases you have to hide an application from your computer...
In the follow step you will learn how to hide an application from start up menu, from "add / remove" / "programs" list. Of course the application will be accessible and fully functional. In any case this way of hide will have result to hide an application from simple users and not from technicians... but is a good way to hide an application.

difficulty: 7/10 (expert users)

compatibility: winxp, win vista, win7


let's work...



Solution:
1. disable viewer hidden folders open "my computer" go tools -> folder options -> view -> advanced settings -> check "do not show hidden files, folders or driver" if it is not.

2. create your "secret folder" to open in future hidden applications and to keep a backup 
2.1. create a folder where will be not easy accessible;
2.2 save somewhere the full address of this secret folder;
2.3. make the folder hidden (right click on it -> properties -> check the "hidden");
2.4. from now on, your secret folder will be accessible only for the full address you did previously, just copy paste it in the address bar of the windows explorer (i.e. my computer).

3. now, open your secret folder and create two subfolders with the follow names: "menus", "uninstall". get into "menus" folder and leave the window open.

4. move the applications shortcuts from startup menu 
4.1. open the start up, go to start -> all programs; here are listed all the installed programs,
4.2. with right click move all the shortcuts and folders of programs you want to hide to the "menus" window (you left previously open)

5. remove the last used programs click the "start" and on the left there the "recently opened programs", click on each program you want to hide and click "remove from the list". I suggest you to remove all;

6. optionally hide the "recently opened programs"; right click on "start" -> properties -> start menu -> uncheck "store and display recently opened programs in start menu" and the other check bellow next of it.

7. hide the "program files" folder go to "start" -> "run" there type "%programfiles%" (without quotes) and in the window will be opened will show to you the list of the applications where are really installed. No click on each folder you want to hide and do: "properties" -> check "hidden" -> ok

8. hide data folders of the application go to "start" -> "run" there type "%AppData%" (without quotes) and in the window will be opened, click on each folder you want to hide and do: "properties" -> check "hidden" -> ok

9. change your default programs if you try to hide for i.e. the microsoft office, the .docx files will remain available to be opened from winword.exe; because of this your .docx files will have the icons of the microsoft word; to change this... icon, just right click of a .docx file, select "open with" select the "wordpad" (of some else) application and check it as default program. This operation must be done for all other types of files that are opened from the applications you want to hide. You have to change the default application for each file. In the specific example "hiding microsoft office" I suggest you to install the "open office" also http://www.openoffice.org/ and make the open office as default program for your office documents.

and the last one and the most difficult...

10. hide the applications from the "add / remove" or "program list" from control panel.
Of course we will take backup, in order to uninstall in future the application you want, otherwise you will can't uninstall it!
10.1. open the "uninstall" folder you did in your secret folder, and copy the full address at your clipboard.
10.2. open the registry editor (start -> run -> regedit)
10.3. go to at key
HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall  
& and for 64bit systems at key
HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall
10.4. in this list of "uninstall" folder you see several keys with GUID names... like "{5EB6F3CB-46F4-451F-A028-7F6D8D35D7D0}" these keys are code names of each application you have installed in your computer. Selecting each of these keys you see on the right list of the registry editor the keys of this GUID. On the right, at  the value of key named "Display Name" you see the name of the application. So, from the value of this key you can see which application is this GUID.
Now apply the follow steps for each application you want to hide
Backup the uninstall direction
10.5.1. On the left list, under the "uninstall" folder, right click on the GUID where is the application you want to hide.
10.5.2. Select export and paste from the clipboard the address of the "uninstall" folder of your hidden folder you did on step 9.1. As filename type the name of the application in order to know for which application is this backup.
Remove the application from with system's uninstall list

10.5.3. Right click again on this GUID and no select "delete", "are you sure?" -> "Yes"
10.5.4. Do a restart or re-login to take effect

other minorities...

11. disable search (in w7 & vista) right click on "start button" -> properties -> tab: start menu -> customize, at the end of the list find and uncheck the setting named: "search programs and control panel".

Congratulations! The operation is completed... now applications are hidden and the only way to launch them is from your secret folder\menus where are the shortcut of the applications.

What we did is that we hid the shortcuts of the applications, the folder that are commonly use and we hid them from the uninstall list of the windows system. It is safe as we didn't change something from the settings of the applications.

In any case, if an application is not so "microsoft windows compatible" might be confused if will try to see a folder and cannot be found, because now it is hidden. In general this problem is no occurred in popular (and windows compatible) applications.

Rollback- turn the explorer to see the hidden folders
- make no hidden the folders you did
- copy back the "menus" folders of your hidden folder at start up folder; (right click on "all programs" menu and then choose "explore" to see the start up folder easy)
- to activate the uninstall directions and appear again the applications in the "add / remove" "program list" an control panel, go to at "uninstall" folder of your secret folder, and run the registry file for the application you want to activate. do a restart or re-login to take effect.

Flex4, Flex3, how to load an html to TextArea with htmlText property

problem: 
not something important... how to load a simple html file... or a plain text file

solution:
In this example I will create the "l" object where is a URLLoader.
The TextArea object is the "ta_plateu" object where is at "main" module on design time.
I have placed the htmlText: "Loading... please wait..."; this text will be appeared to the user till the download is completed and with this text I can discriminate if I have downloaded or not the text. (Of course this is not the perfect discrimination way, and it doesn't work well if the loaded text contains the "Loading..." text also).
use the follow code... accordingly:somewhere in your code you have to request the file...
      if (main.ta_plateu.htmlText.search("Loading...")>-1) {
        var l:URLLoader = new URLLoader;l.dataFormat=URLLoaderDataFormat.BINARY;
        l.load(new URLRequest("http://www.mycompany.com/docs/plateu_ital_text.html"));
        l.addEventListener(Event.COMPLETE,Plateu_download_completed);
      }
now you have to implement the listener "Plateu_download_completed" where will be triggered when the download is completed:
    public function Plateu_download_completed(event:Event):void{
      main.ta_plateu.htmlText=URLLoader(event.target).data;
    }

notes:
On this example are not checked the error conditions... you have to implement and the other events like I have done Event.COMPLETE.
Also the "l" object is not global in the class. Multiple call of the 1st block where you do the download request will have no so good performance. Its better to define the "l" object in the class (not in a function of your class) and remove the event listener in the "Plateu_download_completed" function.

Friday 11 March 2011

escape characters to cut paper

situation:
this solution if for 80mm printers, also known as kitchen printers or receipt printers.
EPSON PRINTER (pcl)


problem:
how to cut the paper or open the drawer

solution:

escape characters to cut paper +#27+#100+#08+#27+#105 +#27+#07;
open drawer 1 +#27+#112+#0+#96+#255;
open drawer 2: +#27+#112+#1+#96+#255;