Hi all
I am trying to implement hit object in my project. I have sprite class and I
am loading multiple instances of UI Loader in my sprite class and displaying
it on the main screen. The user can drag and drop those UILoaders on the
main stage wherever they want.My aim was that if user drops one UIloader on
top of already placed UiLoader, then the already placed UILoader will be
replaced with the dropped UILoader. I am successful in implementing that by
hitting hitTestObject method. All of my UIloaders are having green color
border. Now my requirement is that as soon as the user places UILoader on
top of already existing UILoader , the  UILoader which is going to be
replaced changes border color from green to red showing the user that the
UIloader is being replaced and on Mouse release the UiLoader is going to be
replaced.
In short on mouse over, the border color has to be changed and on mouse
release, object has to be replaced. I am adding my rectangle(in Sprite
Container) as the border to the UILoader. Below is some code to make things
little clearer
Please help me in figuring out the problem.
Any help will be appreciated.
Thanks
Anuj
/*********************CODE********************
//UILoader Being Created
    function CreateUILoaderObject(num:Number):DisplayObject
    {
        var myUILoader:UILoader = new UILoader();
        var  container:Sprite=new Sprite();
        myUILoader.name="myUILoader";
        myUILoader.source = "/video/pic_"+(num+1)+".swf";
        myUILoader.load();

        //Defining Border for the Selected Camera
        var ldrBdr:Sprite = new Sprite();
        ldrBdr.name = "border";
        ldrBdr.alpha=0;
        ldrBdr.graphics.lineStyle(2, 0x00ff00);
        ldrBdr.graphics.drawRect(myUILoader.x+23, myUILoader.y+45,
myUILoader.width, myUILoader.height);

        //Defining Border for the replaced Camera
        var BdrRep:Sprite=new Sprite();
        BdrRep.name="RepBorder";
        BdrRep.alpha=0;
        ldrBdr.graphics.lineStyle(2, 0x00ff00);
        ldrBdr.graphics.drawRect(myUILoader.x+23, myUILoader.y+45,
myUILoader.width, myUILoader.height);

        myUILoader.addChild(ldrBdr);
        myUILoader.addChild(BdrRep);
        container.addChild(myUILoader);


        //Enabling Dragging & Dropping of Video Loader Anywhere
        myUILoader.addEventListener(MouseEvent.MOUSE_DOWN,dragUILoader);
        myUILoader.addEventListener(MouseEvent.MOUSE_UP,dropUILoader);
        myUILoader.addEventListener(MouseEvent.MOUSE_OVER,showBorder);
        myUILoader.addEventListener(MouseEvent.MOUSE_OUT,hideBorder);
        return myUILoader;
    }

    //Show the selected Camera with green Border
        function showBorder(e:MouseEvent):void
        {
            e.target.getChildByName("border").alpha=1;
        }
        function hideBorder(e:MouseEvent):void
        {
            e.target.getChildByName("border").alpha=0;
        }
    //UILoader to be replaced
     function dropUILoader(e:MouseEvent):void
        {

            if(e.target    is UILoader)
            {
                var myUILoader:UILoader = e.target as UILoader;

            if (mouseY<746)
            {
                myUILoader.stopDrag();
              var trackChild:Number=container.getChildIndex(myUILoader);
               var childContainer:DisplayObject= container.getChildAt
(trackChild);
                        for (var z:Number=0; z<=container.numChildren-1;
z++)
                        {
                            var restChild:DisplayObject=container.getChildAt
(z);
                            if ((childContainer!=restChild)&&(
childContainer.hitTestObject(restChild))==true)
                            {
                                container.removeChild(restChild);
                            }
                        }
                    }
_______________________________________________
Flashcoders mailing list
Flashcoders@chattyfig.figleaf.com
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders

Reply via email to