Drawing a Flex Group to a bitmap, then attaching it - actionscript-3

A little context: I want to animate in a popup (extends Spark Group) in Flex using the Greensock Tweenlite class. I have an elastic ease that I'm really keen on but when I tween the scale of my popup, the text in the Flex Group jumps around a little, wiggles, and generally looks bad until the tween has come to a halt.
I've considered fading in the text once the intro animation has completed, but I'm not happy with that solution. My only other option (as far as I can see it) is to draw the entire group to a bitmap, include that bitmap in the popup, hide the rest of the content in the popup, and remove the bitmap (and reveal the "real" content) once the tween has completed.
No idea how to do this in Flex, though, since I can't addChild(bitmap) in there.
Here's a simplified version of my code.
<fx:Script>
<![CDATA[
import com.greensock.TweenLite;
import com.greensock.easing.Elastic;
import com.greensock.plugins.TweenPlugin;
import mx.events.FlexEvent;
private function creationComplete(event : FlexEvent) : void
{
addEventListener(MouseEvent.CLICK,
function (m : MouseEvent) : void {
TweenLite.killTweensOf(rect);
TweenLite.killTweensOf(content);
TweenLite.fromTo(rect,
.8,
{
scaleX: .8,
scaleY: .8
},
{
scaleX: 1,
scaleY: 1,
ease: Elastic.easeOut
});
});
}
]]>
</fx:Script>
<s:HGroup width="100%"
height="100%"
horizontalAlign="center"
verticalAlign="middle">
<s:Group id="rect"
width="120"
height="120">
<s:Rect width="100%"
height="100%"
radiusX="10"
radiusY="10">
<s:fill>
<s:SolidColor color="0x000000" />
</s:fill>
</s:Rect>
<s:VGroup id="content"
width="100%"
height="100%"
padding="10"
horizontalAlign="center"
verticalAlign="middle">
<s:Label width="100%"
text="Hello world foo bar abcdefg 123 Hello world foo bar abcdefg 123 Hello world foo bar abcdefg 123"
color="0xffffff" />
</s:VGroup>
</s:Group>
</s:HGroup>

I figured it out. Did what I planned out and after a little more research found the BitmapImage class.
Final code:
<fx:Script>
<![CDATA[
import com.greensock.TweenLite;
import com.greensock.easing.Elastic;
import mx.events.FlexEvent;
private function creationComplete(event : FlexEvent) : void
{
addEventListener(MouseEvent.CLICK,
function (m : MouseEvent) : void {
var bitmapData : BitmapData = new BitmapData(content.width,
content.height,
true,
0x000000);
bitmapData.draw(content);
bitmapImage.source = bitmapData;
bitmapImage.visible = true;
content.visible = false;
trace(bitmapImage.smoothingQuality);
TweenLite.killTweensOf(rect);
TweenLite.killTweensOf(content);
TweenLite.fromTo(rect,
.8,
{
scaleX: .8,
scaleY: .8
},
{
scaleX: 1,
scaleY: 1,
ease: Elastic.easeOut,
onComplete: onComplete
});
});
}
private function onComplete() : void
{
bitmapImage.visible = false;
content.visible = true;
}
]]>
</fx:Script>
<s:HGroup width="100%"
height="100%"
horizontalAlign="center"
verticalAlign="middle">
<s:Group id="rect"
width="120"
height="120">
<s:Rect width="100%"
height="100%"
radiusX="10"
radiusY="10">
<s:fill>
<s:SolidColor color="0x999999" />
</s:fill>
</s:Rect>
<s:BitmapImage id="bitmapImage"
smooth="true"
smoothingQuality="high" />
<s:VGroup id="content"
width="100%"
height="100%"
padding="10"
horizontalAlign="center"
verticalAlign="middle">
<s:TextInput width="100%"
text="Hello world foo bar abcdefg 123 Hello world foo bar abcdefg 123 Hello world foo bar abcdefg 123"
color="0x0000ff" />
</s:VGroup>
</s:Group>
</s:HGroup>

Related

flex 4 skinning button control

i am working on a flash video player, it is having a default skin for control bar. now what i need to do is, to change the skin of the player mainly control bar with the background image/color .
any suggestions
<mx:Button id="btnBuy" height="29" label="Watch Full Video" chromeColor="#B92420"
click="btnBuy_clickHandler(event)" color="#FFFFFF" fontFamily="Verdana"
fontSize="9" fontWeight="bold" paddingLeft="0" paddingRight="0"
skin="{BuyButtonSkin}"/>
Skin file
<!-- host component -->
<fx:Metadata>
<![CDATA[
[HostComponent("spark.components.Button")]
]]>
</fx:Metadata>
<fx:Script>
<![CDATA[
import controllers.DataController;
import mx.events.FlexEvent;
[Bindable]
[Embed(source='resources/images/ico-button.png')]
private var img:Class;
[Bindable]
[Embed(source='resources/images/ico-buy-hover.png')]
private var img2:Class;
[Bindable]
[Embed(source='resources/images/ico-button-wl.png')]
private var imgWL:Class;
[Bindable]
[Embed(source='resources/images/ico-buy-hover-wl.png')]
private var img2WL:Class;
]]>
</fx:Script>
<!-- states -->
<s:states>
<s:State name="up" />
<s:State name="over" />
<s:State name="down" />
<s:State name="disabled" />
</s:states>
<s:Rect left="0" right="0" top="0" bottom="0" >
<s:fill>
<s:SolidColor color="0x000000" alpha="1" />
</s:fill>
</s:Rect>
<fx:Style>
.backgroundImage {
fontSize: 18;
fontStyle: italic;
contentBackgroundColor: #FFFFFF ;
backgroundImage: Embed("resources/images/ico-button.png");
backgroundImageFillMode: repeat;
}
</fx:Style>
<s:BorderContainer width="100%" height="100%" styleName="backgroundImage" borderAlpha="0">
</s:BorderContainer>
<!--<components:ImageRepeatCanvas includeIn="up, disabled, down" width="100%" height="100%"
repeatDirection="horizantal" id="BuyNowBtn" repeatImage="{DataController.white_label? imgWL : img}"
dropShadowVisible.up="false">
</components:ImageRepeatCanvas>
<components:ImageRepeatCanvas repeatDirection="horizantal" id="BuyNowBtnHover" repeatImage="{DataController.white_label? img2WL : img2 }" width="100%" height="100%" includeIn="over">
</components:ImageRepeatCanvas>-->
There's an example in the Flex documentation that deals with this.
In your skin class:
<fx:Script>
override protected function updateDisplayList(unscaleWidth:Number, unscaledHeight:Number):void {
// Push style values into the graphics properties before calling super.updateDisplayList
backgroundFill.color = getStyle("backgroundColor");
// Call super.updateDisplayList to do the rest of the work
super.updateDisplayList(unscaledWidth, unscaledHeight);
}
</fx:Script>
...
<s:Rect left="0" right="0" top="0" bottom="0" >
<s:fill>
<s:SolidColor id="backgroundFill" color="0x000000" alpha="1" />
</s:fill>
</s:Rect>
And in your display class, assuming you dispatch a DataEvent from the network service handler with the color value:
private function responseListener(e:DataEvent):void {
btnBuy.setStyle("color", e.data);
}

How to use "this" in Flash Builder 4.5

I'm trying to learn Flash builder 4.5, and now I'm stuck with this question.
I got this code:
<fx:Script>
<![CDATA[
public function showList():void
{
tier2.x=(this.x+this.width);
tier2.y=(this.y+this.height);
tier2.visible=true;
}
]]>
</fx:Script>
// on mouseover I'm calling function showList()
<mx:LinkButton x="10" y="20" width="143"
label="Class 1" id="t_id1"
mouseOver="showList()"
color="#FFFFFF" fontFamily="Arial" fontSize="16" fontWeight="bold"/>
<s:List id="tier2" visible="false" width="111" borderColor="#FEFEFE"
borderVisible="true" color="#FAF3F3" contentBackgroundAlpha="0.5"
contentBackgroundColor="#5D5E5E">
</s:List>
In function showList() I'm trying to move the list to the linkbutton on mouseover.
How can I get the linkbutton's x and y position?

flex spark list Drag and drop an item on a spark canvas component

i have a spark list that displays a list of images that represent products. i am trying to implement a drag and drop functionality that allows the user to drag the products he wants to buy from the list to canvas area where he can see the products he choose before buying them. i am using the code below but i cannot figure out what is wrong with it , it seems that i am unable to use the list item as a draginitiator, can any one help please:
private function onMouseDown( event : MouseEvent ) : void
{
var list:List = List(event.currentTarget);
var dragInitiator:Image = Image (list.selectedItem);
var source : DragSource = new DragSource();
source.addData(dragInitiator, "img");
DragManager.doDrag(dragInitiator, source, event);
}
protected function canvas1_dragEnterHandler(event:DragEvent):void
{
DragManager.acceptDragDrop(Canvas(event.currentTarget));
}
protected function canvas1_dragDropHandler(event:DragEvent):void
{
Image(event.dragInitiator).x =
Canvas(event.currentTarget).mouseX;
Image(event.dragInitiator).y =
Canvas(event.currentTarget).mouseY; }
<fx:Model id="categoriesModel" source="Data/Categories.xml"/>
<s:ArrayList id="CategoriesCollection" source="{categoriesModel.Category}"/>
<fx:Model id="productsModel" source="Data/Products.xml"/>
<s:ArrayList id="ProductsCollection" source="{productsModel.Product}" />
</fx:Declarations>
<s:VGroup gap="5" horizontalAlign="center">
<s:HGroup gap="5">
<Components:PROExpressLogo/>
<s:List id="categoryList" scroller="{null}" visible="true"
itemRenderer="Renderers.categoryItemRenderer" width="700" borderAlpha="0"
change="categoryList_changeHandler(event)">
<s:layout>
<s:HorizontalLayout/>
</s:layout>
</s:List>
</s:HGroup>
<s:List id="productList" scroller="{null}" contentBackgroundAlpha="0.4" contentBackgroundColor="0xabcdef"
itemRenderer="Renderers.productItemRenderer" width="880" borderAlpha="0" visible="true" horizontalCenter="0"
dragEnabled="false" mouseDown="onMouseDown(event)"
>
<s:layout>
<s:HorizontalLayout/>
</s:layout>
</s:List>
<s:HGroup gap="20">
<s:Group>
<s:Image id="planImage" width="500" height="300" horizontalCenter="0"
toolTip="Drag your items on your Plan and drop them were you plan to install them"
/>
<mx:Canvas width="500" height="300" backgroundAlpha="0.1"
backgroundColor="#abcdef" borderColor="#abcdef" borderStyle="inset"
contentBackgroundColor="#abcdef" cornerRadius="10"
dragDrop="canvas1_dragDropHandler(event)"
dragEnter="canvas1_dragEnterHandler(event)" dropShadowVisible="true"
horizontalCenter="0"/>
</s:Group>
<s:List id="cart" width="200" height="300"/>
</s:HGroup>
I 'm thinking you need add drag initiator should be the item renderer that you are dragging rather than the entire List control.
Not list.selectedItem that simple object that is not like UIComponent or VisualElement you have to point some ui component like group.

Heirarchical davanced datagrid with itemrenderer in flex4

I had done Hierarchical advanced data grid with image and button renderers using itemRenderers.
Herer the link for image:- Image
In the attached image, u can see the item renderes are not aligned properly. i had read few updates from this blog and applied spark renderer for creating item renderer class.
I created itemrenderer uisng s:MXAdvancedDataGridItemRenderer class.
Please check the below code for button renderer class :-
<s:layout>
<s:HorizontalLayout verticalAlign="middle" horizontalAlign="center" paddingLeft="6" paddingTop="0" paddingRight="6" paddingBottom="0"/>
</s:layout>
<fx:Declarations>
<!-- Place non-visual elements (e.g., services, value objects) here -->
</fx:Declarations>
<fx:Script>
<![CDATA[
import com.common.ImageLibrary;
import mx.controls.Alert;
import mx.resources.ResourceManager;
override public function set data(value:Object):void
{
super.data = value;
var showButton:String;
if(value.hasOwnProperty("Data_Transfer") )
{
showButton = value.Data_Transfer;
if (showButton == "Show_Button") {
startId.visible= true;
startId.includeInLayout= true;
abortId.visible= true;
abortId.includeInLayout= true;
imgStatus.visible=false;
lblStatus.visible= false;
imgStatus.includeInLayout= false;
lblStatus.includeInLayout= false;
}else {
startId.visible= false;
abortId.visible= false;
startId.includeInLayout= false;
abortId.includeInLayout= false;
imgStatus.includeInLayout= true;
lblStatus.includeInLayout= true;
lblStatus.text = "--";
}
}
}
]]>
</fx:Script>
<s:HGroup width="100%" gap="5" verticalAlign="middle" horizontalAlign="left" height="100%">
<!--<mx:Image id="imgStatus"/>
<s:Label id="lblStatus" textAlign="left" showTruncationTip="true" paddingTop="3"/>-->
<s:VGroup height="50%" verticalAlign="middle" horizontalAlign="center">
<s:Button label="Start" id="startId"/>
<s:Button label="Abort" id="abortId" />
</s:VGroup>
<s:HGroup height="100%">
<mx:Image id="imgStatus" includeInLayout="false"/>
<s:Label id="lblStatus" textAlign="left" showTruncationTip="true" paddingTop="3" />
</s:HGroup>
</s:HGroup>
`
and the renderer is also not working properly. i have to show the buttons in the parent row and show the label and image in the child row. but the renderer is not working peroperly.
please let me know , if have any solution for this issue.

AS3 ViewStack content clipping

I have the next code (Flash Builder 4.5)
This main appliction file, for testing me viewstack component.
TabPanelTest
</fx:Declarations>
<fx:Script>
<![CDATA[
import mx.events.FlexEvent;
protected function creationCompleteHandler(event:FlexEvent):void
{
tp.AddPanel("111", new Button());
tp.AddPanel("444", new TestPanel());
tp.AddPanel("2222222", new Button());
tp.AddPanel("3333333333", new Button());
}
protected function button1_clickHandler(event:MouseEvent):void
{
// TODO Auto-generated method stub
tp.RemoveAllPanels();
}
]]>
</fx:Script>
<ns1:TabPanel id="tp" x="25" y="27" width="321" height="199">
</ns1:TabPanel>
<s:Button x="439" y="25" label="Кнопка1" click="button1_clickHandler(event)"/>
</s:Application>
This is TabPanel, that have public methods AddPanel and RemoveAllPanels.
TabPanel
protected function creationCompleteHandler(event:FlexEvent):void
{
//buttons1.dataProvider=new ArrayCollection();
}
public function AddPanel(name:String, element:IVisualElement):void{
var panel:NavigatorContent=new NavigatorContent();
panel.label=name;
panel.addElement(element);
panels.addElement(panel);
}
public function RemoveAllPanels():void{
//panels.swapElements(swapElementsAt(0,2);
panels.removeAllElements();
/*var but:Button;
but=new Button();
but.label=name;
buttons.addElement(but); */
}
]]>
</fx:Script>
<mx:ViewStack id="panels" x="0" y="31" width="100%" height="100%" borderColor="#000000"
borderStyle="solid" borderVisible="true" clipContent="true" includeInLayout="true">
</mx:ViewStack>
<s:ButtonBar id="buttons1" x="0" y="0" width="100%" dataProvider="{panels}"
justificationStyle="pushOutOnly"/>
</s:Group>
This is testing panel, that have size more than viewstack, and it must clipping.
TestPanel
<?xml version="1.0" encoding="utf-8"?>
<s:Group 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="100%" height="100%">
<fx:Script>
<![CDATA[
import spark.components.NavigatorContent;
protected function button1_clickHandler(event:MouseEvent):void
{
// TODO Auto-generated method stub
NavigatorContent(this.parent.parent.parent).label="bebe";
}
]]>
</fx:Script>
<fx:Declarations>
</fx:Declarations>
<s:Button x="163" y="35" width="315" height="209" label="Кнопка"
click="button1_clickHandler(event)"/>
</s:Group>
When i click to "444" in buuton bar my content don't clipping. What's problem?
Problem is in this line with TestPanel custom component: -
<s:Button x="163" y="35" width="315" height="209" label="Кнопка"
click="button1_clickHandler(event)"/>
If you are adding any component to parent container: -
child component will consider x and y position with respect to parent.
If you want to fit your child component you should use x=0 and y=0
as well as width = 100% and height = 100%
Try this and see out put: -
<s:Button x="163" y="35" width="100%" height="100%" label="Кнопка"
click="button1_clickHandler(event)"/>
Again Try this and see out put: -
<s:Button x="0" y="0" width="100%" height="100%" label="Кнопка"
click="button1_clickHandler(event)"/>
You will come to know how component behavior.
Hope this may solve your problem.....