Bindable variable not updating with viewstack / swiz - apache-flex

I'm using the Swiz framework and I'm trying to update my viewstack's selectedIndex with a bindable property. It gets to my event handler which updates the bindable variable but the Main app file's viewstack never realizes it. What could be the issue?
thx
-Mike
================================
MAIN APP FILE
<mx:Script>
<![CDATA[
import reg.model.ApplicationViewModel;
import beyaz.reg.swiz.SwizBeans;
import org.swizframework.Swiz;
[Autowire(bean="applicationViewModel")]
[Bindable]
public var applicationViewModel:ApplicationViewModel;
private function preInitialize():void {
Swiz.loadBeans( [ SwizBeans ] );
}
]]>
</mx:Script>
<mx:ViewStack id="theViewstack" **selectedIndex=" {applicationViewModel.mainViewIndex}"** width="100%" height="100%">
<prescreen:Prescreen id="prescreenView"/>
<login:Login id="loginView"/>
<profile:Profile id="profileView"/>
</mx:ViewStack>
=================================
ApplicationViewModel
package com.reg.model
{
public class ApplicationViewModel
{
public static const PRESCREEN_VIEW:int = 0;
public static const LOGIN_VIEW:int = 1;
public static const PRSNL_INFO_VIEW:int = 2;
[Bindable]
public var message:String = "";
[Bindable]
public var mainViewIndex:int = PRESCREEN_VIEW;
}
}
===========================
Controller
package com.reg.controller
{
import com.reg.model.ApplicationViewModel;
import mx.collections.ArrayCollection;
import mx.controls.Alert;
import mx.events.DynamicEvent;
import mx.rpc.events.FaultEvent;
import mx.rpc.events.ResultEvent;
import mx.core.Application;
import org.swizframework.Swiz;
import org.swizframework.controller.AbstractController;
public class PrescreenController// extends AbstractController
{
public static const START_REGISTRATION:String = "startReg";
[Autowire(bean="applicationViewModel")]
[Bindable]
public var applicationViewModel:ApplicationViewModel;
[Mediate(event="startReg")]
public function startReg():void
{
//CODE GETS TO HERE!
applicationViewModel.mainViewIndex = ApplicationViewModel.PRSNL_INFO_VIEW;
}
}
}

I got bit by this problem just last week.
Put your [Bindable] tag before the other tags. For some reason the Flex compiler doesn't fold in the appropriate PropertyChangeEvent dispatching unless you put the [Bindable] tag first.

Related

could not be able set labelField of List Control in flex 4.6

I'm not able to set the Label of List Control which I first save to SQLite database and then show that as lebelField of List control my code is following :
List of Cities mxml is :
<?xml version="1.0" encoding="utf-8"?>
<s:View xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark" title="Cities"
>
<fx:Declarations>
<!-- Place non-visual elements (e.g., services, value objects) here -->
</fx:Declarations>
<fx:Script>
<![CDATA[
import model.DataModel;
import mx.collections.ArrayCollection;
import mx.events.FlexEvent;
import mx.events.IndexChangedEvent;
import spark.components.SplitViewNavigator;
import spark.components.ViewNavigator;
import spark.transitions.ViewTransitionBase;
protected function myList_changeHandler():void {
// Create a reference to the SplitViewNavigator.
var splitNavigator:SplitViewNavigator = navigator.parentNavigator as SplitViewNavigator;
// Create a reference to the ViewNavigator for the Detail frame.
var detailNavigator:ViewNavigator = splitNavigator.getViewNavigatorAt(1) as ViewNavigator;
detailNavigator.transitionsEnabled = false;
// Change the view of the Detail frame based on the selected List item.
detailNavigator.pushView(DisplayContents, list_of_cities.selectedItem);
}
]]>
</fx:Script>
<s:VGroup width="100%" height="100%">
<s:List id="list_of_cities" height="100%" width="100%" change="myList_changeHandler();"
dataProvider="{DataModel.getInstance().cityList}">
</s:List>
</s:VGroup>
city value object is ::
package valueobject
{
[Bindable]
public class CityValueObject
{
public var id:uint;
public var nameofcity:String;
}}
and DataModel is ::
package model
{
import flash.data.SQLConnection;
import mx.collections.ArrayCollection;
[Bindable]
public class DataModel
{
public var connection:SQLConnection;
public var cityList:ArrayCollection = new ArrayCollection();
public var logs:String="Application Logs........\n";
public static var _instance:DataModel;
public static function getInstance():DataModel
{
if(_instance == null)
{
_instance = new DataModel();
}
return _instance;
}
}}
and CityUtilities class is:
package utillities
{
import flash.data.SQLResult;
import flash.data.SQLStatement;
import flash.display.Loader;
import flash.display.LoaderInfo;
import flash.events.Event;
import flash.net.URLRequest;
import flash.utils.ByteArray;
import model.DataModel;
import mx.collections.Sort;
import mx.collections.SortField;
import valueobject.CityValueObject;
public class CityUtils
{
public static function getAllCities():void
{
var contactListStatement:SQLStatement = new SQLStatement();
contactListStatement.sqlConnection = DataModel.getInstance().connection;
contactListStatement.text = "SELECT * FROM CITYNAME";
contactListStatement.execute();
var result:SQLResult = contactListStatement.getResult();
if( result.data!=null)
{
DataModel.getInstance().cityList.removeAll();
for(var count:uint=0;count<result.data.length;count++)
{
var cityVO:CityValueObject = new CityValueObject();
cityVO.id = result.data[count].id;
cityVO.nameofcity = result.data[count].city;
DataModel.getInstance().cityList.addItem(cityVO);
}
}
sortData();
}
public static function sortData():void
{
var dataSortField:SortField = new SortField();
dataSortField.name = "nameofcity";
dataSortField.numeric = false;
/* Create the Sort object and add the SortField object created earlier to the array of fields to sort on. */
var numericDataSort:Sort = new Sort();
numericDataSort.fields = [dataSortField];
/* Set the ArrayCollection object's sort property to our custom sort, and refresh the ArrayCollection. */
DataModel.getInstance().cityList.sort = numericDataSort;
DataModel.getInstance().cityList.refresh();
}
public static function updateLog(newLog:String):void
{
DataModel.getInstance().logs += new Date().time+" :-> "+newLog+"\n";
}
}}
Please tell me how to set labelField according to SQLite nameofcity column thanks in advance
You need to display nameofcity means set LabelField property for spark list like following
<s:VGroup width="100%" height="100%">
<s:List id="list_of_cities" height="100%" width="100%" labelField="nameofcity" change="myList_changeHandler();"
dataProvider="{DataModel.getInstance().cityList}">
</s:List>
if it shows [object CityValueObject] then create custom ItemRenderer then override data method
override public function set data(value:Object):void
{
super.data = value;
var vo:CityValueObject=value as CityValueObject;
lblCityName.text = vo.nameofcity.toString();
}
All other code is correct, but mistake is that I placed
for(var count:uint=0;count<result.data.length;count++)
{
var cityVO:CityValueObject = new CityValueObject();
cityVO.id = result.data[count].id;
//cityVO.nameofcity = result.data[count].city; // Here I should Have written like
cityVO.nameofcity = result.data[count].nameofcity;// this works as I needed
DataModel.getInstance().cityList.addItem(cityVO);
}

Can't figure out why I'm getting an "Access of undefined object" error in Flex 4.5

I'm very new to Flex 4.5 and I created a class (Project.as) with the following code in it:
package classes
{
public class Project
{
public var projectName:String;
public var description:String;
public var fileLoc:String;
public function Project()
{
// This is the constructor
}
public function SayHello() {
import mx.controls.Alert;
Alert.show('howdy!','Greeting');
}
}
}
In my main.mxml file, I have the following code:
<fx:Script>
<![CDATA[
import classes.Project;
import mx.controls.Alert;
public var aProject:Project = new Project;
aProject.SayHello();
]]>
</fx:Script>
And Flex Builder is saying this:
1120: Access of undefined property aProject.
Why is it telling me this, and how can I fix it? I don't see why it's not working.
Lots of issues here.
First, I have never seen anyone put import statements inside a method. Usually they are put between the package and class definition:
package classes
{
import mx.controls.Alert;
public class Project
{
public var projectName:String;
public var description:String;
public var fileLoc:String;
public function Project()
{
// This is the constructor
}
public function SayHello() {
Alert.show('howdy!','Greeting');
}
}
}
Second; the line of ActionSCript code that you write to call a method on your class instance should be placed inside a method; not "random". Like this:
<fx:Script>
<![CDATA[
import classes.Project;
import mx.controls.Alert;
public var aProject:Project = new Project;
protected function sayHello():void{
aProject.SayHello();
}
]]>
</fx:Script>
Some way you'll want to call that method. A commenter on the original post suggested using creationComplete, which would work. However, you should be cautious about using creationComplete for "constructor-style" code in an MXML Component. preinitialize is better, and the event will fire right after the actual constructor runs. If you need to access any MXML children, have your code in an initialize event handler which runs right after createChildren() runs.
creationComplete handlers execute right after the component finishes initializing; and people often do things in creationComplete that make the component go through it's Lifecycle again, updating the display list.

Alert Box Class

I want to make a reusable Alert Box Class which will be instantiated on various screens of my Flex Project.
Can some tell me whats next in the code below, because am sort of lost regarding how to set the message and title and how to call the Class in my project?
Any help.
Thanks
package components
{
import mx.controls.Alert;
import mx.core.mx_internal;
public class myAlertBox extends Alert
{
public function AlertBoza()
{
super();
var a:Alert;
}
override public static function show():void{
}
}
}
You do not need to extend Alert since the Alert.show() function is static. But you can set it as follows inserting a constructor for a message string and a class member. With that cou can just call the class with the constructor and show the alertbox.
package components
{
import mx.controls.Alert;
import mx.core.mx_internal;
public class myAlertBox
{
private var message:String;
public function myAlertBox(message:String = "")
{
super();
this.message = message;
}
public function show():void{
Alert.show(message);
}
}
}
In another class you can call:
var box:myAlertBox = new myAlertBox("Error");
myAlertBox.show();
If you just want to show a simple alert box, just use mx.controls.Alert directly as you can specify the title and the message show then:
import mx.controls.Alert;
Alert.show("the message", "the title");

how to use actionscript components code in mmxl components

how i can use actionscript component code in mmxl components,as in actionscript components we use classes ,but in mmxl component we can not use classes function, so how i can use actionscript component code in mmxl component
example,,
this is actionscript component code
package components
{
import assets.*;
import flash.events.*;
import flash.utils.*;
import mx.binding.*;
import mx.containers.*;
import mx.controls.*;
import mx.core.*;
import mx.events.*;
import mx.styles.*;
public class DialogTitle extends HBox implements IBindingClient
{
private var title:String = "TitleDialog";
public var DialogTitle1Image1:Image;
public var DialogTitle2Image2:Image;
public var DialogTitle3Label1:Label;
var _bindingsBeginWithWord:Object;
private var showCloseButton:Boolean = false;
var _bindingsByDestination:Object;
var _watchers:Array;
var _bindings:Array;
private var _documentDescriptor_:UIComponentDescriptor;
private static var _watcherSetupUtil:IWatcherSetupUtil;
but i cant use this code in mmxl components how i can use public class DialogTitle extends HBox implements IBindingClient in mmxl component code,what are the way to use it,sorry i am newbie if it is silly question
Here's how you can derive class from HBox and make it implement interface:
<?xml version="1.0" encoding="utf-8"?>
<mx:HBox
implements="com.interfaces.IBindingClient"
>
<mx:Script>
<![CDATA[
//and code goes here
]]>
</mx:Script>
</mx:HBox>
Note that interface must be specified with full path, imports have no effect on it.

Loading of external SWF results in a "Could not find resource bundle messaging" error

I'm using flash.display.Loader to load this example SWF as a use-case for loading SWFs that uses flex charting components in an application I'm working on.
This is the code I'm using to load the swf:
Main.mxml:
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" creationComplete="onCreationComplete(event);">
<mx:Script>
<![CDATA[
import mx.events.FlexEvent;
import myLoaderClass;
private function onCreationComplete( e:FlexEvent ):void
{
trace("Init!");
var l:myLoaderClass = new myLoaderClass();
this.addChild(l);
}
]]>
</mx:Script>
</mx:Application>
myLoaderClass:
package
{
import mx.core.UIComponent;
import flash.display.DisplayObject;
import flash.display.DisplayObjectContainer;
import flash.display.Loader;
import flash.display.Sprite;
import flash.display.StageAlign;
import flash.display.StageScaleMode;
import flash.events.Event;
import flash.events.ProgressEvent;
import flash.net.URLRequest;
import flash.text.TextField;
import flash.text.TextFieldType;
import flash.utils.Dictionary;
public class JittRunner extends UIComponent
{
private var displayedObjects:Dictionary;
public function JittRunner():void
{
displayedObjects = new Dictionary();
if (stage) init();
else addEventListener(Event.ADDED_TO_STAGE, init);
}
private function init(e:Event = null):void
{
removeEventListener(Event.ADDED_TO_STAGE, init);
var mLoader:Loader = new Loader();
var mRequest:URLRequest = new URLRequest('ChartSampler.swf');
mLoader.load(mRequest);
}
}
}
The thing is, the minute the swf is loaded I'm getting the following runtime error:
Error: Could not find resource bundle messaging
at mx.resources::ResourceBundle$/getResourceBundle()[C:\autobuild\3.5.0\frameworks\projects\framework\src\mx\resources\ResourceBundle.as:143]
at mx.utils::Translator$cinit()
at global$init()
at mx.messaging.config::ServerConfig$cinit()
at global$init()
at _app_FlexInit$/init()
at mx.managers::SystemManager/http://www.adobe.com/2006/flex/mx/internal::docFrameHandler()[C:\autobuild\3.5.0\frameworks\projects\framework\src\mx\managers\SystemManager.as:3217]
at mx.managers::SystemManager/docFrameListener()[C:\autobuild\3.5.0\frameworks\projects\framework\src\mx\managers\SystemManager.as:3069]
What am I doing wrong here?
I don't think you're not doing anything wrong in the code you posted. I just pasted it into a new project (renamed JittRunner to myLoaderClass) and it compiled and ran fine (didn't do anything but no errors).

Resources