Flex printing using FlexPrintJob

วันนี้ว่างๆ ก็เลยนั่งลองหาดูว่า Flex มันติดต่อเครื่องพิมพ์ได้อย่างไร ก็เลยไปเจอเข้าว่ามันใช้ FlexPrintJob ในการทำงาน คล้ายๆกับ Java เลยที่ใช้ PrintJop แล้วก็ Draw Graphic ลงไปเอา

ส่วน FlexPrintJob ก็คล้ายๆกัน แต่เอา Component ยัดลงไปได้เลย

  1. Create an instance of the FlexPrintJob class
  2. var printJob:FlexPrintJob = new FlexPrintJob();
  3. Start the print job:
  4. printJob.start();
  5. Add one or more objects to the print job and specify how to scale them:
  6. printJob.addObject(myObject, FlexPrintJobScaleType.MATCH_WIDTH);
  7. Send the print job to the printer:
  8. printJob.send();
  9. Free up any unneeded objects.

Continue reading “Flex printing using FlexPrintJob” »

Flex Callback Function

public function firstFunction():void{ trace("call first function") } public function secondFunction(callbackFunction:Function):void{ trace("call second function") callbackFunction() } public function thirdFunction():void{ trace("call third function") }

Validate Data in DataGrid

itemEditBegin – Fired when you click on an editable cell of the datagrid (also when the editedItemPosition is set on an editable DataGrid)

itemEditBeginning – Fired when the mouse is released

itemEditEnd – Fired when the edit is committed / editor is destroyed there by terminating the edit session.

1 2 3 [...]

Creating a view cursor on an ArrayCollection in Flex

ปกติเวลาจะหา data จาก ArrayCollection ก็จะวนลูปแล้ว if เอา วันนี้เล่นเน็ตไปมาเลยไปเจอว่าเค้าทำกันแบบนี้ได้

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
< ?xml version="1.0" encoding="utf-8"?>
<!-- http://blog.flexexamples.com/2008/04/15/creating-a-view-cursor-on-an-arraycollection-in-flex/ -->
<mx:application xmlns:mx="http://www.adobe.com/2006/mxml"
        layout="vertical"
        verticalAlign="middle"
        backgroundColor="white"
        creationComplete="init();">
 
    <mx:array id="arr">
        <mx:string>One</mx:string>
        <mx:string>Two</mx:string>
        <mx:string>Three</mx:string>
        <mx:string>Four</mx:string>
        <mx:string>Five</mx:string>
    </mx:array>
 
    <mx:arraycollection id="arrColl" source="{arr}" />
 
    <mx:script>
        < ![CDATA[
            import mx.collections.IViewCursor;
            import mx.collections.Sort;
            import mx.collections.SortField;
 
            [Embed("assets/accept.png")]
            public var acceptIcon:Class;
 
            [Embed("assets/exclamation.png")]
            public var exclamationIcon:Class;
 
            private var cursor:IViewCursor;
 
            private function init():void {
                var sortField:SortField = new SortField(null, true);
                var sort:Sort = new Sort();
                sort.fields = [sortField];
 
                arrColl.sort = sort;
                arrColl.refresh();
 
                cursor = arrColl.createCursor();
            }
 
            private function button_click(evt:MouseEvent):void {
                var found:Boolean = cursor.findAny(textInput.text);
                if (found) {
                    img.source = acceptIcon;
                    list.selectedItem = cursor.current;
                } else {
                    img.source = exclamationIcon;
                    list.selectedItem = null;
                }
            }
        ]]>
    </mx:script>
 
    <mx:applicationcontrolbar dock="true">
        <mx:canvas>
            <mx:textinput id="textInput" />
            <mx:image id="img" right="3" verticalCenter="0" />
        </mx:canvas>
        <mx:button id="button"
                label="Find"
                click="button_click(event);" />
    </mx:applicationcontrolbar>
 
    <mx:list id="list"
            dataProvider="{arrColl}"
            width="100"
            rowCount="{arrColl.length}" />
 
</mx:application>

ผลการรันก็ได้อย่างนี้คับ
Continue reading “Creating a view cursor on an ArrayCollection in Flex” »

Cloning ArrayCollection

There are plenty of occasions where you might want to be able to create an exact clone of a complex/nested data objects, without your new object simply referencing the old one’s values. To do this, you need to force the creation of new values and references. Depending on the complexity of the data stored, this will be achieved through shallow or deep copying:

Continue reading “Cloning ArrayCollection” »