2 Replies Latest reply on Nov 12, 2007 2:28 AM by Akshay_Gautam

    Problem Identifing A Visual Component

    Akshay_Gautam
      Hi, I am stuck in a situation where I am using an ActionScript visual custom component, which extends a VBox container. Lets call this component as MyComponent here. This MyComponent includes several other visual components viz, labels, a grid and 6 images inside the grid. All images have been assigned an id to uniquely identify each of them.

      I am using this visual custom ActionScript component inside a Grid recursively. Now I want to identify each of the MyComponent's images from those Grid elements.

      Please suggest me a way to identify which image of MyComponent I am referring to, as I am using MyComponent, where the position of image is inside mycomponent's grid's element position."

      Also intimate me about the user_names and other authentications required for respective forums you are registering to.

      Akshay.
        • 1. Re: Problem Identifing A Visual Component
          Gregory Lafrance
          I would think you could either refer to the MyComponent instances in the Grid by getChildAt or perhaps create IDs on the fly as they are created by appending a number within a loop.
          • 2. Re: Problem Identifing A Visual Component
            Akshay_Gautam Level 1
            Hi,

            Thanks for the reply. The problem lies in identifying the component while clicking on the image. Here I have an array of mouse images in the Cage class. I want to identify which arrMouse instance is being clicked on the Grid.

            Here is the code where I am calling my component with name Cage.

            private function addGrid():Grid
            {
            var gridRows:int = 10;
            var gridCols:int = 5;

            var lGrid:Grid = new Grid();

            var arrGridRow:Array = new Array(gridRows);
            var arrGridCol:Array = new Array(gridCols);

            for (var rowNum:int = 1; rowNum <= gridRows; rowNum++)
            {
            arrGridRow[rowNum] = new GridRow();

            for (var colNum:int = 1; colNum <= gridCols; colNum++)
            {
            arrGridCol[colNum] = new GridItem();

            var cageNew:Cage = new Cage();

            arrGridCol[colNum].addChild(cageNew);
            arrGridRow[rowNum].addChild(arrGridCol[colNum]);
            }

            lGrid.addChild(arrGridRow[rowNum]);
            }

            return lGrid;
            }



            Here is my component class Cage:

            public class Cage extends VBox
            {
            //These variables are for creating visual components.
            private var cageDesc:HBox;
            private var cageName:Label;
            private var cageGenotype:Label;
            private var cageNo:Label;
            private var mouseRack:Grid;
            private var mouseRackRow:GridRow;
            private var mouseRackRowItem:GridItem;
            //private var mouse1:Image;
            private var arrMouse:Array = new Array(total_slots);
            private var timer:Image;

            //This is the only property added for this class.
            [Inspectable(defaultValue="From Class")]
            private var _txtVal:String;

            //These variables are for RemoteObject related functions.
            private var mouseRO:RemoteObject;
            private var cage_id:int = 344;
            private var slot_id:int;
            private var total_slots:int = 5;

            public var mouseGender:int;
            private var event:ResultEvent;

            public function Cage()
            {
            addEventListener(FlexEvent.INITIALIZE, initializeHandler);
            }

            public function get txtVal():String
            {
            return _txtVal;
            }

            public function set txtVal(value:String):void
            {
            _txtVal = value;
            //dispatchEvent(new Event("numButtonsChange"));
            }

            public function useRemoteObject():void
            {
            mouseRO = new RemoteObject();

            mouseRO.source = "cfide.samples.test.cf.institution";
            mouseRO.destination = "ColdFusion";
            mouseRO.GetMouseByCageId.addEventListener("result", GetMouseInfoResultHandler);

            mouseRO.addEventListener("fault", faultHandler);
            mouseRO.GetMouseByCageId(cage_id, slot_id);
            Alert
            //here 344 is cage_id and 1 is slot_id.
            }

            public function GetMouseInfoResultHandler(event:ResultEvent):void
            {
            mouseGender = event.result.getItemAt(0).mouse_gender_id;
            //Alert.show(String(event.result.getItemAt(0).mouse_gender_id));
            //Alert.show(String(mouseGender));

            }

            private function faultHandler(event:FaultEvent):void
            {
            // Deal with event.faultstring, etc.
            Alert.show(event.fault.faultString, 'Error');
            }

            // Gets called when the component has been initialized
            private function initializeHandler(event:FlexEvent):void
            {
            // Display the component
            paint();
            }

            private function paint():void
            {
            // Create the number cageDesc
            cageDesc = new HBox();
            cageName = new Label();
            timer = new Image();

            cageName.width=90;
            cageName.height=16;
            cageName.text=_txtVal;

            timer = new Image();
            timer.source = "../Assets/clocktimerGray.gif";

            cageDesc.addChild(cageName);
            cageDesc.addChild(timer);
            addChild(cageDesc);

            cageGenotype = new Label();
            cageGenotype.width=90;
            cageGenotype.height=16;
            cageGenotype.text="GenoType";
            addChild(cageGenotype);

            cageNo = new Label();
            cageNo.width=90;
            cageNo.height=16;
            cageNo.text="CageNo";
            addChild(cageNo);

            mouseRack = new Grid();
            mouseRackRow = new GridRow();
            mouseRackRowItem = new GridItem();

            for(slot_id = 1; slot_id <= 5; slot_id++)
            {
            useRemoteObject();
            arrMouse[slot_id] = new Image();

            Alert.show(String(mouseGender));

            switch(mouseGender)
            {
            case 1:
            arrMouse[slot_id].source = "../Assets/mouseMale.gif";
            break;
            case 2:
            arrMouse[slot_id].source = "../Assets/mouseFemale.gif";
            break;
            case 3:
            arrMouse[slot_id].source = "../Assets/mouseOther.gif";
            break;
            case 4:
            arrMouse[slot_id].source = "../Assets/mouseOther.gif";
            break;
            default:
            arrMouse[slot_id].source = "../Assets/mouseGray.gif";
            break;
            }

            mouseRackRowItem.addChild(arrMouse[slot_id]);
            }
            /*mouse1 = new Image();
            mouse1.source = "../Assets/mouseGray.gif";
            mouseRackRowItem.addChild(mouse1);*/

            mouseRackRow.addChild(mouseRackRowItem);
            mouseRack.addChild(mouseRackRow);
            addChild(mouseRack);
            }

            }

            Now when I am clicking on any image of arrMouse array in the visual display, I am unable to get the instance of mouse

            clicked.
            Please suggest me some way of accessing the arrMouse array element image.