1

I have a flash inside and iFrame and i want to click through iFrame but not through flash. I have seen that, we can click through iFrame via "pointer-events: none;" but it passes everything inside iframe. Now I just want to know, that can we enable or check the mouse click in flash?

I have added an sample for my question. black dots are in a flash swf file and its in iFrame. Now when I click on transparent area then it should be clicked on underneath area that is Label buttons in this case. otherwise black dots should be clicked.

Click Underneath Flash

VarunJi
  • 685
  • 2
  • 14
  • 31
  • do you mean you want to be able to click what is underneath the flash content in the iframe (it being on top of something)? I am afraid I don't understand the entire problem. – lemieuxster Sep 06 '14 at 05:53
  • Yes, I want to click underneath part of flash transparent area. Flash is on top and HTML buttons are in under flash iframe. – VarunJi Sep 08 '14 at 07:14
  • I have updated my question with snapshot. So please let me know, if you can help. – VarunJi Sep 08 '14 at 08:39

2 Answers2

1

I think it doesn't matter if you are in iframe in this case, if I understand correctly you want a pass-through click from Flash to the underlying HTML page, but only if the click doesn't satisfy some condition (in this case, only if it's not over the black spots).

An approach would be to do it collaboratively between the Flash part and some JavaScript part in the iframe:

  • Intercept the click in Flash, get coordinates and verify if it's over a black circle
  • If it is, handle the corresponding logic in Flash, else proceed with the following steps
  • Pass the coordinates to a JavaScript function already defined in the iframe through Flash's external interface
  • Finally in the JavaScript you can do something along the lines of How to simulate a click by using x,y coordinates in JavaScript?
Community
  • 1
  • 1
circlespainter
  • 836
  • 5
  • 8
  • Thanks Circlespainter for your answer. But unfortunately, these circles positions and shapes are animated. So i cann't apply this logic. I tried in IE Browser for wmode=transparent and its working fine there, but not in Chrome and Firefox. – VarunJi Sep 11 '14 at 09:03
  • Yes, wmode=transparent can be troublesome and can have a relevant performance impact. Can't you just make your flash logic smarter by tracking circles' position? – circlespainter Sep 11 '14 at 09:50
1

To do list :

  1. Use the CSS attribute pointer-events: none; on iframe
  2. Create a invisible div with ID="event-eater" that covers the elements.
  3. Add Javascript below (uses jQuery) to recognizance where click happened
  4. It will call actionscript method ClickPosition and based on returned result do 1 of following
    • If black area was clicked - Do nothing, click event was created in actionscript
    • If background was clicked - Temporally hide current element, and recreate click in javascript

Javascript

$('#event-eater').click(function(evt) {
    var posX = $(this).offset().left, posY = $(this).offset().top;
    var x = Math.abs(Math.round(evt.pageX - posX));
    var y = Math.abs(Math.round(evt.pageY - posY));
    var result = "["+x+", "+y+"]";
    if(document['flashInterface'].ClickPosition(result)=="true"){
        $('#event-eater').css({display:'none'});
        starter = document.elementFromPoint(evt.clientX, evt.clientY);
        $(starter).click();
        $('#event-eater').css({display:''});
    };
});

Actionscript

package
{
    import fl.events.ColorPickerEvent;
    import flash.display.MovieClip;
    import flash.external.ExternalInterface;
    public class Main extends MovieClip {
        //set this variable true if background was clicked last, false otherwise
        var wasBackgroundClickedLast:Boolean = new Boolean(true)
        public function Main() {
            //allows JavaScript to access the ClickPosition() function.
            ExternalInterface.addCallback("ClickPosition", clickPosition);  
        }
        public function clickPosition(value:String):String{
            var va= str.split(",");
            simulateClick(Number(va[0]),Number(va[1]));
            return wasBackgroundClicked.toString();
        }
        public function simulateClick(x:Number, y:Number):void
        {
            var objects:Array = stage.getObjectsUnderPoint(new Point(x, y));
            var target:DisplayObject;
            while(target = objects.pop()){if(target is InteractiveObject){ break; }}
            if(target !== null)
            {
                var local:Point = target.globalToLocal(new Point(x, y));
                var e:MouseEvent = new MouseEvent(
                    MouseEvent.CLICK, true, false, local.x, local.y);
                target.dispatchEvent(e);
            }
        }
    }
}

Small demo : Javascript eventeater with button array below it.

Margus
  • 19,694
  • 14
  • 55
  • 103
  • Note this is not tested, but I am quite confident it should work. You want to add thread sleep 0.1s after simulateClick from actionscript side. You still need to add **wasBackgroundClickedLast = false** when black circle is clicked and **...=true** if background was clicked. – Margus Sep 11 '14 at 12:34
  • Example on how communication between javascript and actionscript work : http://code.tutsplus.com/tutorials/quick-tip-how-to-communicate-between-flash-and-javascript--active-3370 – Margus Sep 11 '14 at 12:35
  • It might be easier to host HTML inside flash, but might not. – Margus Sep 11 '14 at 12:42
  • Thanks for your answer Margus. There could be anything underneat, like flash or HTML or anything related to web. I can handle HTML clicks in this case, but not the Flash. So what could be the solution for Flash click, if flash is underneath that iframe? – VarunJi Sep 11 '14 at 14:45
  • 1
    My small demo shows how to click through and element. Other then that I can only recommend not to use iframe - use div or something. – Margus Sep 11 '14 at 15:16
  • Anyway... Thanks Margus for your answer. I am still in trouble yet for sucking flash object :( – VarunJi Sep 11 '14 at 15:27