Kun Janos around Adobe’s <Flex> and <Flash>

about me, my life and my work

Archive for October, 2008

Alternative for ViewStack.selectedIndex

Posted by admin on 31st October 2008

ViewStacks are great for storing containers and showing the one that is needed.
You can use the view stacks selectedIndex property for changing between the different views. However, by using the selectedIndex, often you have to change the indexes, because in case you comment or remove a container the indexes are changing for the views that are remaining.
The view stack has a selectedChild property, where you can set the view that needs to be shown by his id, but for using that in any part of the application, you should have access to the container.
Instead of using the id, I came up with a solution by using the containers name. Here it is:

<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" 
	layout="absolute" 
	xmlns:local="*" >
 
	<mx:Script>
		<![CDATA[
			import mx.core.Container;
			import mx.core.UIComponent;
 
			[Bindable] public static var STACK_CONTENT_NAME_1:String = 'stack1';
			[Bindable] public static var STACK_CONTENT_NAME_2:String = 'stack2';
			[Bindable] public static var STACK_CONTENT_NAME_3:String = 'stack3';
			[Bindable] public static var STACK_CONTENT_NAME_4:String = 'stack4';
 
			private function onClick():void{
				myViewStack.selectedChild = myViewStack.getChildByName(STACK_CONTENT_NAME_3) as Container;
			}
 
		]]>
	</mx:Script>	
	<mx:VBox>
 
		<mx:LinkBar dataProvider="{myViewStack}" />
		<mx:ViewStack id="myViewStack">
			<mx:HBox label="ViewStack Item #1" name="{STACK_CONTENT_NAME_1}">
				<mx:Label text="ViewStack Content #1" />
			</mx:HBox>
			<mx:HBox label="ViewStack Item #2" name="{STACK_CONTENT_NAME_2}">
				<mx:Label text="ViewStack Content #2" />
			</mx:HBox>
			<mx:HBox label="ViewStack Item #3" name="{STACK_CONTENT_NAME_3}">
				<mx:Label text="ViewStack Content #3" />
			</mx:HBox>
			<mx:HBox label="ViewStack Item #4" name="{STACK_CONTENT_NAME_4}">
				<mx:Label text="ViewStack Content #4" />
			</mx:HBox>
		</mx:ViewStack>	
		<mx:Button label="change" click="onClick()" />
	</mx:VBox>
</mx:Application>

Posted in <Flex> | No Comments »

Reading and Writing Local Files in Flash Player 10

Posted by admin on 22nd October 2008

Flash player prior to version 10 was unable to directly read and write data/files from and to the local drives. We could browse for files, upload/download them, but only by using server side script(we are talking about flex applications, not AIR ones). Adobe just made our life a little bit easier, by adding the load() and save() methods to the FileReference class.

Points to keep in mind:

- the location files are not exposed to ActionScript
- we can call the load() and save() APIs only on user action(such as a mouse click)
- The APIs are asynchronous (non-blocking)

You can read more about this on Mike Chambers blog, there are also sample applications to review.

Posted in <Flash>, <Flex> | No Comments »

Flex and Full Screen considerations

Posted by admin on 22nd October 2008

Today I was trying to create a Flex application, that when loaded by the browser will go on full screen. After a few tentatives (that didn’t work of course) I searched the help and found this page about
Programming ActionScript 3.0 > Flash Player APIs > Flash Player Security > Full-screen mode security.
I will highlight the main features here:
- The ActionScript that initiates full-screen mode can be called only in response to a mouse event or keyboard event. If it is called in other situations, Flash Player throws an exception. In other words: bye bye full screen at startup
- Users cannot enter text in text input fields while in full-screen mode. All keyboard input and keyboard-related ActionScript is disabled while in full-screen mode, with the exception of the keyboard shortcuts (such as pressing the Esc key) that return the application to normal mode. This is not cool…Not at all, but I understand. Consider a page that renders a full screen flex window showing a standard Windows log in screen. How many will think that something weird has happened to Windows once again and enter the login credentials into the malicious window :(
- Full-screen mode is always permitted in the stand-alone player or in a projector file. OK, but who cares? I wanted to do full screen in THE BROWSER.

Posted in <Flex> | No Comments »

Storing custom classes with SharedObject

Posted by admin on 20th October 2008

SharedObject is very useful for storing data on the users local machine. However, if you try to store a custom class and read that data back, you will see that the class became an object and if you try to cast the object to your custom class it won’t work.
The solution for that issue is to put [RemoteClass] before your custom class declaration, like this:

package com.valueObjects{

[Bindable]
[RemoteClass]
public class SharedDataVO {
public var userName: String = '';
}
}

Now, when you write your custom class to the shared object and read it back, the class type will be SharedDataVO just as we expected it to be.

Posted in <Flex> | No Comments »

Flex 3 compiler arguments

Posted by admin on 17th October 2008

Many times we need to use additional compiler settings when building our flex applications. Here is a list, of the options we can use with mxml:
-benchmark
-compiler.accessible
-compiler.actionscript-file-encoding
-compiler.allow-source-path-overlap
-compiler.as3
-compiler.context-root
-compiler.debug
-compiler.defaults-css-url
-compiler.doc
-compiler.es
-compiler.external-library-path [path-element] [...]
-compiler.fonts.languages.language-range
-compiler.fonts.local-fonts-snapshot
-compiler.fonts.managers [manager-class] [...]
-compiler.fonts.max-cached-fonts
-compiler.fonts.max-glyphs-per-face
-compiler.headless-server
-compiler.include-libraries [library] [...]
-compiler.incremental
-compiler.keep-all-type-selectors
-compiler.keep-generated-actionscript
-compiler.library-path [path-element] [...]
-compiler.locale
-compiler.namespaces.namespace
-compiler.optimize
-compiler.profile
-compiler.services
-compiler.show-actionscript-warnings
-compiler.show-binding-warnings
-compiler.show-deprecation-warnings
-compiler.source-path [path-element] [...]
-compiler.strict
-compiler.theme [filename] [...]
-compiler.use-resource-bundle-metadata
-compiler.verbose-stacktraces

-compiler.warn-warning_type

-compiler.warn-array-tostring-changes
-compiler.warn-assignment-within-conditional
-compiler.warn-bad-array-cast
-compiler.warn-bad-bool-assignment
-compiler.warn-bad-date-cast
-compiler.warn-bad-es3-type-method
-compiler.warn-bad-es3-type-prop
-compiler.warn-bad-nan-comparison
-compiler.warn-bad-null-assignment
-compiler.warn-bad-null-comparison
-compiler.warn-bad-undefined-comparison
-compiler.warn-boolean-constructor-with-no-args
-compiler.warn-changes-in-resolve
-compiler.warn-class-is-sealed
-compiler.warn-const-not-initialized
-compiler.warn-constructor-returns-value
-compiler.warn-deprecated-event-handler-error
-compiler.warn-deprecated-function-error
-compiler.warn-deprecated-property-error
-compiler.warn-duplicate-argument-names
-compiler.warn-duplicate-variable-def
-compiler.warn-for-var-in-changes
-compiler.warn-import-hides-class
-compiler.warn-instance-of-changes
-compiler.warn-internal-error
-compiler.warn-level-not-supported
-compiler.warn-missing-namespace-decl
-compiler.warn-negative-uint-literal
-compiler.warn-no-constructor
-compiler.warn-no-explicit-super-call-in-constructor
-compiler.warn-no-type-decl
-compiler.warn-number-from-string-changes
-compiler.warn-scoping-change-in-this
-compiler.warn-slow-text-field-addition
-compiler.warn-unlikely-function-value
-compiler.warn-xml-class-has-changed

-debug-password
-default-background-color
-default-frame-rate
-default-script-limits
-default-size
-dump-config
-externs [symbol] [...]
-file-specs [path-element] [...]
-frames.frame [label] [classname] [...]
-help [keyword] [...]
-includes [symbol] [...]
-lazy-init
-licenses.license
-link-report
-load-config
-load-externs

-metadata.contributor
-metadata.creator
-metadata.date
-metadata.description
-metadata.language
-metadata.localized-description
-metadata.localized-title
-metadata.publisher
-metadata.title

-output
-raw-metadata
-resource-bundle-list
-runtime-shared-libraries [url] [...]
-use-network
-version
-warnings

Posted in <Flex> | No Comments »

Listening for FullScreenEvent.FULL_SCREEN events

Posted by admin on 17th October 2008

Today, while working on one Flex application, I had to add a listener to the stage for FullScreen changes. I thought, this is a simple task, in my
<mx:Application added the creationComplete=”onCreationComplete()” , and defined that function on the Script section, like this:

private function onCreationComplete():void{
stage.addEventListener(FullScreenEvent.FULL_SCREEN, onFullScreenEvent);
}

It compiled without errors, but when running the application I received TypeError: Error #1009: Cannot access a property or method of a null object reference, on the line where I added the listener.
The solution for this is simple, it seems that on the creationComplete event the stage is null, so we need to add our code in the applicationComplete like this: <mx:Application applicationComplete=”onApplicationComplete()”>
and define our function as:
private function onApplicationComplete():void{
//add event listener for the full screen event(stage is null when onCreationComplete, that's why we add the listener here)
stage.addEventListener(FullScreenEvent.FULL_SCREEN, onFullScreenEvent);
}

Posted in <Flex> | No Comments »

Matt Chotin interviewed by Ryan Stewart, sneak preview about Flex 4

Posted by admin on 10th October 2008

I was reading about the next adobe Flex release, named Gumbo.

Flex 4 promises to be one of the best frameworks from Adobe. You can take a look at a general presentation by Matt Chotin about Flex 4 here: http://flexorg.wip3.adobe.com/gumbo/gumboplan.htm

Matt Chotin(he is a product manager on the Adobe Flex team who focuses on the Flex SDK) interviewed by Ryan Stewart video is here, they are talking about the new features in Flex 4.

Posted in <Flex> | No Comments »

Winter is coming :)

Posted by admin on 6th October 2008

This week started to rain and is quite cold out there, its just an autumn day yet and most of the people think: “this sucks”, and they really really hate it. For me, this is a sign, because I enjoy winter :D .

About 20 years ago, we had 1 feet of snow at 1 november, and I hope this year winter will come ASAP. I already changed my cars tiers for mud&snow, and today I will take a look at my skies. At 50 miles from me, there is a ski field, sadly I just find out yesterday, then the road to that is in a very poor condition.

It is funny, how someone can be happy, when they see that the weather is changing from suneshine and cold to rain, mud and cold.

Posted in <free time> | No Comments »