4 Replies Latest reply on May 3, 2010 1:15 AM by dakasadakasadaka

    call from as file to parent mxml

    dakasadakasadaka

      how can I call from .as file function that is in mxml?

      Hier is my mxml where I call carousel.as

      var dCarousel:Carousel = new Carousel();

      pv3dCanvas.rawChildren.addChild(dCarousel);

       

      After that I need from carousel.as to call the function in the .mxml

      function in mxml:

              public function flyToGo():void
              {
                  trace("just testing");
              }

       

      And to call this from carousel.as i tried this:

       

      public function clickPlane(e:InteractiveScene3DEvent):void {
                 
                  trace(e.displayObject3D.material.toString());
                  var obj : Object = this.parent as Object;
                 obj.flyToGo();
                  parent.flyToGo();

                parentApplication.flyToGo();
                    
              }

       

      but non of this works to go to parent function .mxml so how can I go to parent function?

        • 1. Re: call from as file to parent mxml
          David_F57 Level 5

          hi,

           

          All you need to do is add the eventlistener and point it to your click function.

           

           

          var dCarousel:Carousel = new Carousel();

          pv3dCanvas.rawChildren.addChild(dCarousel);

          dCarousel.addEventListener(MouseEvent.CLICK,clickPlane);

           

           

          David.

           

          [edit] clickPlane should be FlyToGo --

          1 person found this helpful
          • 2. Re: call from as file to parent mxml
            dakasadakasadaka Level 1

            Yes but this wasn't the solution for my problem.

            I need to call function from .as to mxml.

            Hier is what I need to make:

            on the mxml is the google maps.... first I call package that makes carousel. Becouse carousel contain information like

            which foto is loaded, which price, which coordinates like lat lan. Then If the user click on the one of the items in the carousel

            I want to pass the lan lat to main mxml, so it can go to that lan lat.

            Ofcourse I could translate carousel package to mxml, but than the codes would be massy!

            • 3. Re: call from as file to parent mxml
              David_F57 Level 5

              hi,

               

              if latitude and longtitude are public in the carousel class then the main mxml still listens for the carousel click event and in that event it has access to the properties

               

              private function flyto(event:MouseEvent): void

              {

               

              mylat = event.currentTarget.latitude;

              mylng= event.currentTarget.longtitude;

               

              }

               

               

              David.

              • 4. Re: call from as file to parent mxml
                dakasadakasadaka Level 1

                still I can't get it:

                In this example I will use public var picturePath:String; as the class that I need in the .mxml

                when user click on plane there is   plane.addEventListener(InteractiveScene3DEvent.OBJECT_CLICK,clickPlane);

                then  public function clickPlane(e:InteractiveScene3DEvent):void {
                             picturePath = e.displayObject3D.material.toString();
                             trace(e.displayObject3D.material.toString());
                            // var obj : Object = this.parent as Object;
                             //parentApplication.flyToGo();
                             //parent.flyToGo();
                          //   trace("hello");       
                         }

                this function needs to set the picturePath to his value.....

                 

                and then from .mxml I need to access picturePath.

                so in .mxml file I just can say trace(picturePath) and it will give me the value???

                 

                This was my setup wich doesn't work

                 

                hier is the carousel.as and mxml file

                package
                {
                    import flash.display.DisplayObject;
                    import flash.display.InteractiveObject;
                    import flash.display.MovieClip;
                    import flash.display.Sprite;
                    import flash.events.Event;
                    import flash.events.MouseEvent;
                    import gs.easing.Quint;
                    import gs.TweenLite;
                    import org.papervision3d.materials.BitmapFileMaterial;
                    import org.papervision3d.objects.DisplayObject3D;
                    import org.papervision3d.objects.primitives.Plane;
                    import org.papervision3d.view.BasicView;
                    import org.papervision3d.cameras.CameraType;
                    import org.papervision3d.events.InteractiveScene3DEvent;
                    import org.papervision3d.objects.DisplayObject3D;
                    import flash.display.Stage;
                import flash.display.StageDisplayState;
                    //import org.papervision3d.cameras.DebugCamera3D;
                    /**
                     * ...
                     * @author Charlie Schulze, charlie[at]woveninteractive[dot]com
                     */
                    public class Carousel extends BasicView
                    {
                        protected var planes:Array = [];
                        protected var numItems:Number = 10;
                        protected var radius:Number = 700;
                        protected var currentItem:Number = 0;
                        protected var mat:BitmapFileMaterial;
                        protected var planesHolder:DisplayObject3D;
                        protected var rightBtn:Sprite;
                        protected var leftBtn:Sprite;
                        public var picturePath:String;
                        //public var dCam = new DebugCamera3D();
                        public function Carousel():void
                        {
                            super();
                            viewport.interactive = true;
                           
                            addEventListener(Event.ENTER_FRAME,beginStageDimensionCheck);
                        }
                       
                        public function beginStageDimensionCheck(e:Event):void {
                            if (stage.stageWidth > 0 && stage.stageHeight > 0) {
                                removeEventListener(Event.ENTER_FRAME,beginStageDimensionCheck); // remove eventListener
                                init(); //execute your script if the value of stageHeight and stageWidth is greater than 0
                            }
                        }
                        protected function init():void
                        {
                            createChildren();
                            //createButtons();
                            commitProperties();
                            onRenderTick();
                            startRendering();
                        }
                       
                        override protected function onRenderTick(e:Event=null):void
                        {
                        planesHolder.localRotationY -=(this.mouseX - stage.stageWidth / 2) / 200;
                        super.onRenderTick();
                        }
                        protected function createChildren():void
                        {
                            planesHolder = new DisplayObject3D();
                            //Create Material
                           
                            for (var i:int = 0; i <numItems; i++)
                            {
                                mat             = new BitmapFileMaterial("images/city"+i+".jpg");
                                mat.smooth   = true;
                                mat.doubleSided = true;
                                mat.interactive = true;
                                //mat.name = "i";
                               
                                var plane:Plane = new Plane(mat, 200, 150);
                                plane.addEventListener(InteractiveScene3DEvent.OBJECT_CLICK,clickPlane);
                                planes.push(plane);
                               
                                //Add plane to the scene
                                planesHolder.addChild(plane);
                            }
                           
                            scene.addChild(planesHolder);
                        }
                        public function clickPlane(e:InteractiveScene3DEvent):void {
                            picturePath = e.displayObject3D.material.toString();
                            trace(e.displayObject3D.material.toString());
                            var obj : Object = this.parent as Object;
                            //parentApplication.flyToGo();
                            //parent.flyToGo();
                            trace("hello");       
                        }
                        protected function commitProperties():void
                        {
                            //Set properties of our planes
                            for (var i:int = 0; i <planes.length; i++)
                            {
                                var angle:Number    = Math.PI * 2 / numItems * i;
                                var plane:Plane     = planes[i];
                                plane.x             = Math.cos(angle) * radius;
                                plane.z             = Math.sin(angle) * radius;
                                plane.rotationY     = -360 / numItems * i - 90;
                            }
                           
                            //Adjust camera
                            camera.y = 180;
                            camera.z = -1200;
                            camera.x = 200;
                            //camera.rotationZ = 0;
                            //camera.rotationX = 0;
                            camera.rotationY = 90;
                            //camera.near = 10;
                           
                            //Rotate once
                            rotate();
                        }
                        //Rotates the carousel
                        protected function rotate():void
                        {
                            var rotateTo:Number = (-360 / numItems) * currentItem + 90;
                            TweenLite.to(planesHolder, 1, { rotationY:rotateTo, ease:Quint.easeInOut } );
                        }
                        /*
                         * Everything below this point is just for creating the buttons and
                         * setting button events for controlling the carousel.
                         */
                        protected function createButtons():void
                        {
                            //Create Buttons
                            rightBtn = createButton();
                            leftBtn = createButton();
                            addChild(leftBtn);
                            addChild(rightBtn);
                            //Add button listeners
                            rightBtn.buttonMode = true;
                            leftBtn.buttonMode = true;
                            rightBtn.addEventListener(MouseEvent.CLICK, buttonClick);
                            leftBtn.addEventListener(MouseEvent.CLICK, buttonClick);
                            //Place buttons on stage
                            //rightBtn.x    = this.stageWidth - 120;
                            //leftBtn.x       = 100;
                            //rightBtn.y    =  this.stageHeight / 2;
                            //leftBtn.y       =  (this.stageHeight / 2) + 20;
                            //leftBtn.rotation    = 180;
                        }
                        //Button actions
                        protected function buttonClick(evt:MouseEvent):void
                        {
                            switch (evt.target)
                            {
                                case rightBtn:
                                currentItem --;
                                break;
                                case leftBtn:
                                currentItem ++;
                                break;
                            }
                            rotate();
                        }
                        //Creates a simple arrow shape / returns the sprite
                        protected function createButton():Sprite
                        {
                            var btn:Sprite = new Sprite();
                            btn.graphics.beginFill(0x333333);
                            btn.graphics.moveTo(0, 0);
                            btn.graphics.lineTo(0, 20);
                            btn.graphics.lineTo(10, 10);
                            btn.graphics.lineTo(0, 0);
                            btn.graphics.endFill();
                            return btn;
                        }
                    }
                    //public function clickPlane(e:InteractiveScene3DEvent):void {
                        //e.DisplayObject3D.Y +=12;       
                //    }
                }

                 

                <?xml version="1.0" encoding="utf-8"?>
                <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" backgroundColor="#FFFFFF">
                <maps:Map3D xmlns:maps="com.google.maps.*" mapevent_mappreinitialize="onMapPreinitialize(event)" mapevent_mapready="onMapReady(event)" id="map" 
                        width="100%" height="100%" key="ABQIAAAA8L7PA6DVZ4iBF69Y-wH1XxTJS7mSMG_76bpXHnj3DLzSC6sgZhQMyuk-p_JMF229R-F0Mr-M89Un Mw" />
                <mx:Script>
                  <![CDATA[
                  import com.google.maps.InfoWindowOptions;
                  import com.google.maps.LatLng;
                  import com.google.maps.Map3D;
                  import com.google.maps.MapEvent;
                  import com.google.maps.MapOptions;
                  import com.google.maps.MapType;
                  import com.google.maps.overlays.Marker;
                  import com.google.maps.overlays.MarkerOptions;
                  import com.google.maps.styles.FillStyle;
                  import com.google.maps.View;
                  import com.google.maps.geom.Attitude;
                  import com.google.maps.controls.NavigationControl;
                  import com.google.maps.controls.ControlPosition;
                  import mx.collections.ArrayCollection;
                  import mx.rpc.events.ResultEvent;
                  import com.google.maps.MapMouseEvent;
                  import TV;
                  import Carousel;
                 
                        //import mx.collections.ArrayCollection;
                        import mx.utils.ArrayUtil;
                        import mx.rpc.events.ResultEvent;
                        import mx.managers.CursorManager;
                        import mx.rpc.events.FaultEvent;
                        import mx.controls.Alert;
                   
                        ////google maps variables
                        public var list:ArrayCollection;
                       
                        public var flyToCord:String;
                       
                        public function flyToGo():void
                        {
                            trace("kkkk");
                        }
                       
                   
                  private function faultHandler(fault:FaultEvent):void
                            {
                                CursorManager.removeBusyCursor();
                                Alert.show("code:\n" + fault.fault.faultCode + "\n\nMessage:\n"
                                                             + fault.fault.faultString + "\n\nDetail:\n" + fault.fault.faultDetail);
                            }

                 


                  private function onMapPreinitialize(event:MapEvent):void {
                    var myMapOptions:MapOptions = new MapOptions();    
                    myMapOptions.zoom = 8.3;
                    myMapOptions.center = new LatLng(44.871442, 15.238037);
                    myMapOptions.mapType = MapType.NORMAL_MAP_TYPE;
                    myMapOptions.viewMode = View.VIEWMODE_PERSPECTIVE;
                    myMapOptions.attitude = new Attitude(70, 70, 0);
                    //myMapOptions.backgroundColor = "#FFFFFF";
                    myMapOptions.backgroundFillStyle = new FillStyle;
                    myMapOptions.backgroundFillStyle.color = 0x70BBF5;

                 

                   
                    map.setInitOptions(myMapOptions);
                    //getMemory();
                  }
                 
                  private function onMapReady(event:MapEvent):void {
                    this.map.addControl(new NavigationControl());
                    //service.send();
                    //getMemory();
                    loadGuestbook();
                    //goMar();
                    var dCarousel:Carousel = new Carousel();
                    //trace(stage.stageWidth, stage.stageHeight);
                     pv3dCanvas.rawChildren.addChild(dCarousel);
                     trace(picturePath);
                     dCarousel.addEventListener(MouseEvent.CLICK,clickPlane);
                }


                private function loadGuestbook():void
                            {
                                GuestbookService.getAllPosts();
                            }

                private function onResult(event:ResultEvent):void {
                    
                               
                        var    list:ArrayCollection = new ArrayCollection( ArrayUtil.toArray(event.result) );
                    // var list:ArrayCollection = event.result.map.loc;
                     for (var i:int = 0; i < list.length; i++)
                     {
                         
                         var name:String = list[i].o_id;
                         var latlng:LatLng = new LatLng(list[i].o_lat, list[i].o_lan);
                        var tvOn : TV = new TV(list[i].o_id);

                 

                         var marker:Marker = createMarker(latlng, name, tvOn);

                 

                        var window:InfoWindowOptions = new InfoWindowOptions( {
                            strokeStyle: {
                               color: 0x987654
                             },
                             fillStyle: {
                               color: 0x223344,
                               alpha: 0.8
                             },
                             contentHTML:list[i].name,
                             width: 200,
                             cornerRadius: 12,
                             padding: 10,
                             hasCloseButton: true,
                             hasTail: true,
                             tailWidth: 20,
                             tailHeight: 30,
                             tailOffset: -12,
                             tailAlign: InfoWindowOptions.ALIGN_LEFT,
                             hasShadow: true
                        });
                        
                        map.addOverlay(marker);
                           

                 

                     }
                    
                    }
                   
                    public function createMarker(latlng:LatLng, name:String, tvOn:Object): Marker {
                          var marker:Marker = new Marker(latlng, new MarkerOptions({tooltip:name, iconAlignment: MarkerOptions.ALIGN_HORIZONTAL_CENTER | MarkerOptions.ALIGN_VERTICAL_CENTER}));
                        var html:String = "<b>" + name;
                        marker.addEventListener(MapMouseEvent.CLICK, function(e:MapMouseEvent):void {
                          marker.openInfoWindow(new InfoWindowOptions({customContent:tvOn, customOffset: new Point(0, 0)}));
                        });
                        return marker;
                     }

                 

                    /*private function getMemory():void {
                        var mem:String = Number( System.totalMemory / 1024 / 1024 ).toFixed( 2 ) + 'MB';
                        trace(mem);
                    }*/
                   
                  ]]>
                </mx:Script>

                 

                    <mx:RemoteObject id="GuestbookService" source="ownerRetriveObjects" destination="amfphp"
                         fault="faultHandler(event)" showBusyCursor="true">
                        <mx:method name="getAllPosts" result="onResult(event)" fault="faultHandler(event)" />

                 

                    </mx:RemoteObject>   
                    <mx:Canvas id="pv3dCanvas"   width="100%" height="100%" horizontalCenter = "0" verticalCenter = "-250"> 
                    </mx:Canvas>
                   
                   
                </mx:Application>