Frustrated Animation Issue - apache-flex

I have spent 2 hours on this simple state to state transition with simply resize and move animation.... I can get the element to move and fade...but there is no resize animation at all. The panel element stay the same width whole time. If I copy the code to a brand new test mxml file, it works, but not in my main application file...I was wondering if someone here can help me out. Thanks a lot.
//This is a custom component inside the main application...Not sure if it relates to my issue.....
<mx:Canvas xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
xmlns:mx="library://ns.adobe.com/flex/mx" width="1000" height="600" xmlns:getcomplist="services.getcomplist.*" xmlns:components="components.*"
currentState="defaultState">
<fx:Script>
<![CDATA[
protected function compList_changeHandler(event:IndexChangeEvent):void
{
currentState="whenClick";
}
]]>
</fx:Script>
<mx:states>
<s:State name="defaultState"/>
<s:State name="whenClick" />
</mx:states>
<mx:transitions>
<s:Transition toState="whenClick">
<s:Parallel target="{animationIsAnnoying}">
<!--<s:Fade duration="1000"/>--> // Fade is working fine...
<s:Resize heightFrom="600" duration="5000" /> //resize is not working
<s:Move xFrom="500" duration="5000" /> //Move is working fine
</s:Parallel>
</s:Transition>
</mx:transitions>
<s:HGroup>
<s:List id="compList"
width="280"
height="500"
change="compList_changeHandler(event)">
</s:List>
<s:Panel id="animationIsAnnoying" height="150" includeIn="whenClick" /> //The panel I want to animated...
<components:compDisplayDetail includeIn="whenClick" id="compDisplay" width="600" height="500" userPic="{userPicResult.lastResult}" dataFromClick ="{compDetailinfoResult.lastResult}" />
</s:HGroup>
</mx:Canvas>

You must have a click event to command the resize component
im using here mx:Resize component
<mx:Resize id="resizeThis" target="{toolBoxContainer}"/>
<mx:VBox id="toolBoxContainer" height="200" width="300" >
<mx:Textid="txt" text="HELLO"/>
</mx:VBox>
<mx:Button id="menuImage"toolTip="Show/Hidden Menu" click="menuClickHandler(event)" toggle="true"/>
<mx:Script>
<![CDATA[
private var toggle:int =1;
private function menuClickHandler(e:MouseEvent):void {
if(toggle == 0 ) {
//MoveThis.end();
resizeThis.widthFrom = 0
resizeThis.widthTo = 46;
resizeThis.play();
}
if(toggle == 1) {
resizeThis.end();
resizeThis.widthFrom = 46
resizeThis.widthTo = 0;
resizeThis.play();
}
if(toggle == 0) toggle = 1;
else toggle = 0;
}
]]>
</mx:Script>
This thing has errors in imports or the likes.. but i assume you got my point..

Related

Draggable Drawer Adobe Flex Mobile

Could someone please assist me with a way to create a drag-able drawer that resides on the bottom of my mobile application? I am wanting to make it so there is a drag handle that is visible all the time (can be an image or whatever) and then allow you to slide the contents into view and slide them back out of view at the bottom of the screen. I am needing a direction to start in, I should be able to figure it out once I have that.
I originally had the sliding initiated on mouse down/move/up events, but have since changed it out for a tap affect (which also occurs when you slide up/down) on the handle image at the top of the dock, since I changed it this afternoon I haven't had a chance to clean it up yet but this is the start:
Drawer:
<?xml version="1.0" encoding="utf-8"?>
<s:Group xmlns:fx="http://ns.adobe.com/mxml/2009" maxHeight="125" minHeight="30" height="30"
xmlns:s="library://ns.adobe.com/flex/spark">
<fx:Script>
<![CDATA[
private var dragging:Boolean = false;
protected function resize():void{
var h:int = this.height;
var i:int = 0;
if (h !== 125){
for(i=h;i<=125;i++){
this.height = i;
};
currentState='up';
return;
}else{
}
if(h >= 30){
for(i=h;i>=30;i--){
this.height = i;
};
currentState='down';
return;
}
}
]]>
</fx:Script>
<fx:Declarations>
<!-- Place non-visual elements (e.g., services, value objects) here -->
</fx:Declarations>
<s:states>
<s:State name="down"/>
<s:State name="up"/>
</s:states>
<s:Rect width="100%" height="100%" top="30">
<s:fill>
<s:SolidColor color="#333333"/>
</s:fill>
</s:Rect>
<s:Image scaleMode="zoom" source.down="#Embed('Images/down.png')" source.up="#Embed('Images/up.png')" mouseDown="resize()"/>
<s:HGroup width="100%" horizontalAlign="center" verticalAlign="bottom" top="30" gap="30">
<!--Buttons here-->
</s:HGroup>
</s:Group>

Is it possible to use outside "<mx:script>" in "<mx:canvas>"?

I got a new project. and some part of it, Flex was exist.
<mx: Application xmlns:mx=...>
<mx:script>
import...
function A() {
}
</mx:script>
<mx:linkBar...>
<mxViewStack ...>
<mx:Canvas id="1st" ...> **[HERE]** </mx:Canvas>
<mx:canvas id="2nd" ...> ... </mx:Canvas>
<mx:canvas id="3rd" ...> ... </mx:Canvas>
** When Viewstack calls Canvas sequentially, A() has to work.
Is it possible to use function A() in **HERE**]?
Or please let me know the possible function or tag which can be used.
Below example may help you: -
<?xml version="1.0" encoding="utf-8"?>
<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
xmlns:mx="library://ns.adobe.com/flex/mx" minWidth="955" minHeight="600">
<fx:Declarations>
<!-- Place non-visual elements (e.g., services, value objects) here -->
</fx:Declarations>
<fx:Script>
<![CDATA[
private function A():void
{
//Your code
}
private function viewStackHandler():void
{
//Method One
if(viewStackID.selectedIndex == 0)
{
A();
}
else if(viewStackID.selectedIndex == 1)
{
A();
}
else
{
A();
}
//OR Method Second
//call only A()
}
]]>
</fx:Script>
<mx:VBox width="100%" height="100%">
<mx:HBox width="100%" height="20">
<s:Button label="One" click="{viewStackID.selectedIndex = 0}"/>
<s:Button label="Two" click="{viewStackID.selectedIndex = 1}"/>
<s:Button label="Three" click="{viewStackID.selectedIndex = 2}"/>
</mx:HBox>
<mx:ViewStack width="500" height="400" id="viewStackID" change="viewStackHandler()">
<mx:Canvas id="canval1" borderColor="#FF0000" width="100%" height="100%">
<s:Button label="One"/>
</mx:Canvas>
<mx:Canvas id="canval2" borderColor="#00FF00" width="100%" height="100%">
<s:Button label="Two"/>
</mx:Canvas>
<mx:Canvas id="canval3" borderColor="#0000FF" width="100%" height="100%">
<s:Button label="Three"/>
</mx:Canvas>
</mx:ViewStack>
</mx:VBox>
</s:Application>
You can use the add attribute which is dispatched when the Canvas is added to the ViewStack
<mx:Canvas id="1st" add="A()"></mx:Canvas>

How to detect whether a list is scrolling or not?

Is there any way to detect whether a list is scrolling or not,likelist.isScrolling
So, #Khaled showed a way to do it with the MX component. If you are using the Spark component, that event doesn't work. Instead, you can listen to changes on myList.scroller.viewport.verticalScrollPosition or horizontalScrollPosition.
<fx:Declarations>
<fx:int id="scrollingCount" />
</fx:Declarations>
<s:initialize>
BindingUtils.bindSetter(function(x:*):void { scrollingCount++; }, myList.scroller.viewport, "verticalScrollPosition");
</s:initialize>
<s:VGroup>
<s:Label text="Scrolling: {scrollingCount}" />
<s:List id="myList" height="200" dataProvider="{myData}" />
</s:VGroup>
In neither of these cases do you get to know when the list stops getting scrolled (I'm not sure if you want it or not). You might have to set a timer and any time the timer goes off without any scrolling events, you are no longer scrolling?
Unfortunately, you haven't explained what you are trying to accomplish, wo we can't adequately answer your question.
Or you can do somme thing like this in a list itemrenderer :
import spark.components.List;
[Bindable]
private var calcWidth:Number=195;
private var listVerticalScroll:Boolean;
private var listHorizontalScroll:Boolean;
override protected function updateDisplayList(unscaledWidth:Number, unscaledHeight:Number):void{
var ownerVerticalScroll:Boolean=List(owner).scroller.verticalScrollBar.visible;
var ownerHorizontalScroll:Boolean=List(owner).scroller.horizontalScrollBar.visible;
if(ownerVerticalScroll!=listVerticalScroll){
listVerticalScroll=ownerVerticalScroll;
scrollBarChange()
}
super.updateDisplayList(unscaledWidth,unscaledHeight);
}
private function scrollBarChange():void {
if(listVerticalScroll){
var newWidth:Number=195-(listVerticalScroll?15:0);
calcWidth=newWidth;
}
}
you can use the ScrollEvent.SCROLL :
import mx.events.ScrollEvent
myList.addEventListener(ScrollEvent.SCROLL, scrollHandler);
function scrollHandler(e:ScrollEvent):void
{
//myList is scrolling
}
Or you can do it like this for spark component!
http://blog.flexexamples.com/2009/05/31/detecting-when-the-vertical-scroll-bar-is-scrolled-on-a-spark-list-control-in-flex-4/ -->
<fx:Script>
<![CDATA[
import spark.components.VScrollBar;
private function init():void {
list.scroller.verticalScrollBar.addEventListener(Event.CHANGE, list_verticalScrollBar_change);
}
private function list_verticalScrollBar_change(evt:Event):void {
var vsb:VScrollBar = evt.currentTarget as VScrollBar;
var obj:Object = {};
obj.type = evt.type;
obj.val = vsb.value;
obj.max = vsb.maximum;
arrColl.addItem(obj);
callLater(dgScroll);
}
private function dgScroll():void {
dataGrid.verticalScrollPosition = dataGrid.maxVerticalScrollPosition;
}
]]>
</fx:Script>
<fx:Declarations>
<mx:ArrayCollection id="arrColl" />
</fx:Declarations>
<s:HGroup horizontalCenter="0" verticalCenter="0">
<s:List id="list"
creationComplete="init();">
<s:layout>
<s:VerticalLayout gap="0"
horizontalAlign="contentJustify"
requestedRowCount="4" />
</s:layout>
<s:dataProvider>
<s:ArrayList>
<fx:String>The</fx:String>
<fx:String>Quick</fx:String>
<fx:String>Brown</fx:String>
<fx:String>Fox</fx:String>
<fx:String>Jumps</fx:String>
<fx:String>Over</fx:String>
<fx:String>The</fx:String>
<fx:String>Lazy</fx:String>
<fx:String>Dog</fx:String>
</s:ArrayList>
</s:dataProvider>
</s:List>
<mx:DataGrid id="dataGrid"
dataProvider="{arrColl}"
width="200"
verticalScrollPolicy="on">
<mx:columns>
<mx:DataGridColumn dataField="type" />
<mx:DataGridColumn dataField="val" />
<mx:DataGridColumn dataField="max" />
</mx:columns>
</mx:DataGrid>
</s:HGroup>
</s:Application>

how to replace the images in flex 3?

In my flex application, i am maintaining 5 images. When user clicks on 'next' button, it should display one image say 'image1'. If that button clicked again, then image1 should replace with image2 and so on. I am basically following 'image.visible' method. But images are displaying side by side. I think it is not the correct procedure. Any alternative? Thanks in advance
here is my code. I kept all my images and buttons in mx:panel. Even i used x and y positions which are not working.
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute">
<mx:Panel
title = 'Learn and Test your Knowledge'
height = '80%'
paddingBottom = '10' paddingTop = '10'
paddingLeft = '10' paddingRight = '10'
borderAlpha='0.20' fontFamily="Verdana" fontSize="15" color="#F30C32" backgroundImage="#Embed(source='../images/lad.jpg')" width="413" x="139">
<mx:Script>
<![CDATA[
public function nextEvent():void
{
// here i should write next button code
}
]]>
</mx:Script>
<mx:Image source="../images/image1.jpg" visible="true" id="image1" />
<mx:Image source="../images/image3.jpg" visible="true" id="image2"/>
<mx:Image source="../images/image3.jpg" visible="true" id="image3"/>
<mx:Button id="next" visible="false" click="nextEvent()">
</mx:Button>
The best way is to use only one image component if you are only ever showing one image. You can create an array or vector with the embedded images and reference that to change the source property on the image component. Here is an example: (the code below will work with any layout/container)
<mx:Canvas xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute">
<mx:Image id="image" click="imageClick()" source="{new images[0]()}" />
<mx:Script>
<![CDATA[
[Embed(source="assets/1.png")]
private var image1:Class;
[Embed(source="assets/2.png")]
private var image2:Class;
[Embed(source="assets/3.png")]
private var image3:Class;
private var images:Array = [image1, image2, image3];
private var imageIndex:uint = 0;
protected function imageClick():void
{
imageIndex++;
if(imageIndex == images.length) imageIndex = 0;
image.source = new images[imageIndex]();
}
]]>
</mx:Script>
</mx:Canvas>
Specify the x and y position of images as same and play around with their visibility.It ll definitely work.
ViewStack is my option it fits very well in this occasion.
At a time it shows only one component, for next action it will automatically override previous content by its new component.
<mx:ViewStack id="myViewStack" borderStyle="solid" width="100%" height="80%">
<mx:Canvas id="one" click="myViewStack.selectedChild=two;">
<mx:Image source="assets/1.png" />
</mx:Canvas>
<mx:Canvas id="two" click="myViewStack.selectedChild=three;">
<mx:Image source="assets/2.png" />
</mx:Canvas>
<mx:Canvas id="three" click="myViewStack.selectedChild=four;">
<mx:Image source="assets/3.png" />
</mx:Canvas>
<mx:Canvas id="four" click="myViewStack.selectedChild=five;">
<mx:Image source="assets/4.png" />
</mx:Canvas>
<mx:Canvas id="five" click="myViewStack.selectedChild=one;">
<mx:Image source="assets/5.png" />
</mx:Canvas>
</mx:ViewStack>

Flex: creating a multi column navigation bar for viewstack

I have created a Viewstack and using a Tile component and repeating LinkButtons I was able to make a multi column navigation with the viewstack as the dataprovider. My question is can this be done better? My code is below and I am wondering if I took the long way around this approach.
<?xml version="1.0" encoding="utf-8"?>
<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
xmlns:mx="library://ns.adobe.com/flex/mx">
<s:layout>
<s:BasicLayout />
</s:layout>
<fx:Script>
<![CDATA[
import mx.controls.Alert;
private var _listItem:Object;
private var n:int=0;
public function get listItem():Object
{
return this._listItem;
}
public function set listItem(listItem:Object):void
{
try{n++;
this.changeSelection(this._listItem);
}catch(e:Error){}
if(n==1 || n > this.viewStack.length){
this._listItem = listItem;
this.changeSelection(listItem);
}
}
private function setSelection(obj:Object):void{
this.viewStack.selectedIndex = this.viewStack.getChildIndex(this.viewStack.getChildByName(obj.target.getRepeaterItem().name));
this.listItem = obj.target;
}
private function checkSelection(obj:Object):void{
if(obj.target.getRepeaterItem() == this.viewStack.selectedChild){
if(this.listItem != obj.target){
this.listItem = obj.target;
}
}
}
private function changeSelection(obj:Object):void{
if(obj.getRepeaterItem() == this.viewStack.selectedChild){
obj.setStyle("color","#000000");
}else{
obj.setStyle("color","#999999");
}
}
]]>
</fx:Script>
<mx:Tile id="tiles" horizontalGap="20" verticalGap="0" y="210" direction="vertical">
<mx:Repeater id="masterList" dataProvider="{viewStack}">
<mx:LinkButton
id="btn"
label="{masterList.currentItem.label}"
click="this.setSelection(event)"
color="#999999"
creationComplete="checkSelection(event);" />
</mx:Repeater>
</mx:Tile>
<mx:ViewStack id="viewStack" height="200" width="300" backgroundColor="#000000" >
<mx:VBox id="vb1" backgroundColor="#FF0000" label="Screen One"/>
<mx:VBox id="vb2" backgroundColor="#00FF00" label="Screen Two"/>
<mx:VBox id="vb3" backgroundColor="#0000FF" label="Screen Three"/>
<mx:VBox id="vb4" backgroundColor="#00FFFF" label="Screen Four"/>
</mx:ViewStack>
</s:Application>
Looks to me like you've got navigation links that expose different and that those links change color based on which one is selected. Assuming that's the case, it sounds an awful lot like a tab-based navigation model. My approach would be to use the spark TabBar and skin the tabs to look like links. That way you can get rid of most of your code and let the tab skin handle changing the colors based on their current state. Also, you wouldn't need any of the code you have for changing the view stack since the TabBar would handle that for you. Hope that helps.

Resources