Browser scrolling problem when mouse inside flash content area
Posted on March 16, 2010
Sometimes we are struck with unusual behaviours of flash when used inside HTML. One of these problems is the user unable to scroll the page when mouse is inside flash content area and the user has to manually drag the scrollbars to scroll the page.
The reason is pretty simple !!!.
“wmode” property of of object tag is default set to “window” which affects scrolling and flash takes control over mouse scrolling events of the browser window.
The solution is again pretty forward.
Change the ‘wmode‘ property to either ‘opaque‘ or ‘transparent‘ according to need. I would recommend using opaque in general case as transparency cost some CPU cycles at run time.
Filed Under AS3 | Leave a Comment »
AIR security flaw
Posted on July 20, 2009
Opening a new browser out side any AIR application will dispose the url variables on the browser.
Although it’s not 100% logical to put this claim on AIR applications because that is meant for desktop application and have least relation with external browsers, it’s an issue that you may get some time while launching any external browser( ‘external’ means not inside AIR application itself). This problem creates security flaws when you are opening a browser against some authenticated data or session. Even if use ‘post’ method to send the urlvariables, they wont be hidden on the browser.
Here is one example where you can find such trouble.
-
<?xml version="1.0" encoding="utf-8"?>
-
<mx:WindowedApplication xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute">
-
<mx:Button x="399" y="305" label="Button" click="getUI()" />
-
-
<mx:Script>
-
<![CDATA[
-
private function getUI():void{
-
var re:URLRequest=new URLRequest("http://localhost/url/check.php");
-
re.method=flash.net.URLRequestMethod.POST;
-
-
var urlv:URLVariables=new URLVariables;
-
urlv.desc=5;
-
re.data=urlv;
-
navigateToURL(re,"_self");
-
}
-
]]>
-
</mx:Script>
-
-
</mx:WindowedApplication>
When you run this example it will open a browser and will show the variable name and value where as if you write the same sort of code in for web application it would not show the ‘desc=5′ in the browser.
A sample piece of same code is given below which is implemented for a mouse click event on button.
-
abc_mc.addEventListener(MouseEvent.CLICK, ola);
-
-
function ola(e:MouseEvent):void{
-
var re:URLRequest=new URLRequest("http://localhost/url/check.php");
-
re.method=flash.net.URLRequestMethod.POST;
-
-
var urlv:URLVariables=new URLVariables;
-
urlv.desc=5;
-
re.data=urlv;
-
navigateToURL(re,"_blank");
-
}
The php code used in the test is as follows:
-
<?
-
$test=$_REQUEST[‘desc’];
-
echo $test;
-
?>
-
So be sure you should never pass any data while opening some browser.
Filed Under AIR, AS3 | Leave a Comment »
Prevent XML caching problem
Posted on June 8, 2009
When load xml files by URLLoaders, they are often cached by the browsers and do flash is unable to display the updated data. This is a very common problem & I always find this some where around me once in a month or so. Even my friends do face the same issue.
There is a very simple solution to this cute little problem. When ever you are loading by URLLoader.load method just add a time stamp to the URLRequest and everything will work fine except you might get some error message while compiling the swf.(”Error #2044: Unhandled ioError:. text=Error #2032: Stream Error. URL”). You can ignore it and continue publishing. On the web it will not throw any such error- believe me.
Here is the little rabbit:
-
var xmlPath:String="replaceYourXMLPathHere.xml"
-
var urlReq:URLRequest = new URLRequest(xmlPath+"?time=" + new Date().getTime());
Let me know if the readers have some other idea..
Filed Under AS3 | 2 Comments »
AS3 Event Handling- part 6
Posted on April 17, 2009
In this small part of action script event handling we will learn about one of the effective event handling technique that can help us to dispose our objects towards garbage collection( I will be writing about this interesting topic soon.)- in other way we can make efficient application without causing any memory leaking. The rule of thumb is to make use of removeListener and remove any event listener attached to some object before you remove or delete it by either removeChild or delete method.
When ever we create objects and attach events with them, events go on executing if that object resides in memory. Let me give you one small example:
Create a movieClip instance on the stage and give it a name ( foo_mc in my example). Now on the first frame open action panel and write down code for ENTER_FRAME event of that movielClip and then remove the foo_mc. The example code is given below:
-
foo_mc.addEventListener(Event.ENTER_FRAME, trackObject);
-
-
function trackObject(evt:Event){
-
removeChild(foo_mc);
-
trace("I am executing");
-
}
When you execute this code, even if you have removed the child by removeChild method, it will not be removed from memory and trackObject function will be executing. Even if you add foo_mc=null, it will still execute the function. The reason is foo_mc is not deleted completely from memory at this point of time. It may be removed latter some time when garbage collector will see foo_mc does not have any reference to other objects. Here this loop of enter frame will go on because foo_mc has a listener to the enter frame event. One thing you should always remember that removeChild() never removes display objects from memory, it only removes from it’s parents display list. If this situation arises then it’s always wise to remove the event listener attached to it before you remove it from the display list. Also it’s a good programming practice to make the methods of a n object to null when not required in future so that they won’t eat up some memory. This case grow bigger when there are conditions for looping. So a better code may look like this:
-
foo_mc.addEventListener(Event.ENTER_FRAME, trackObject);
-
-
function trackObject(evt:Event){
-
foo_mc.removeEventListener(Event.ENTER_FRAME, trackObject);
-
removeChild(foo_mc);
-
trace("I am executing");
-
}
If you feel some thing different about this, please share with me.
Filed Under AS3, Flash, Flex 3.0 | 1 Comment »
AS3 Event Handling- part 5
Posted on April 10, 2009
Previous part of AS3 Event Handling series was about creating custom event class. In this part we will look at the one of the mostly unused parameters in addEventListener method handler.
addEventListener is the method used to add an listener to an object for a specified event. Hence we usually pass two parameters ( first one is the event name and second event handler name) and everything works perfectly. But if you need more control over the event flow you may be interested in the other parameters available. The other three parameters are useCapture, priority & useWeakReference. We will discuss about the first one in this part.
useCapture
This parameter tells about processing of event object in the phases of the event propagation. The default value is false, means event object can provide information about the target phase and the bubbling phase and not about the capture phase.
To understand the exact behaviour let’s create one small flash file and write some code. Open an AS3 flash document and create one big rectanglular movieclip and name is as “parent_mc” and a smaller rectangular movieclip inside it and name is as “child_mc“. Now select first frame and write the code. Download the file to see what the trace statements say about mouse down event.
-
parent_mc.addEventListener(MouseEvent.MOUSE_DOWN, truePhase, true);
-
parent_mc.addEventListener(MouseEvent.MOUSE_DOWN, falsePhase, false);
-
-
function truePhase(evt:MouseEvent):void{
-
trace("=====================use capture true===================================");
-
switch(evt.eventPhase){
-
case EventPhase.BUBBLING_PHASE:
-
trace("BUBBLING_PHASE");
-
break;
-
case EventPhase.CAPTURING_PHASE:
-
evt.stopImmediatePropagation();
-
trace("CAPTURING_PHASE");
-
break;
-
case EventPhase.AT_TARGET:
-
trace("AT_TARGET");
-
break;
-
}
-
-
trace("currenttarget: " +evt.currentTarget.name);
-
trace("target: "+evt.target.name);
-
}
-
-
function falsePhase(evt:MouseEvent):void{
-
trace("=====================use capture false===================================");
-
switch(evt.eventPhase){
-
case EventPhase.BUBBLING_PHASE:
-
trace("BUBBLING_PHASE");
-
break;
-
case EventPhase.CAPTURING_PHASE:
-
trace("CAPTURING_PHASE");
-
break;
-
case EventPhase.AT_TARGET:
-
trace("AT_TARGET");
-
break;
-
}
-
-
trace("currenttarget: " +evt.currentTarget.name);
-
trace("target: "+evt.target.name);
-
}
There are two event handlers that handle the mouse down event, it’s because if we set useCapture true then we wont be able to catch the target & bubbling phase. So in two event handlers will handle the event with useCapture true and false respectively. When you down your mouse on the bigger rectangle, you can only see the target as parent_mc and in target phase of propagation. This is because there is no child element under the mouse pointer. Notice that I have added evt.stopImmediatePropagation(); in the first event handler in second switch statement, this blocks further propagation of event and do not let the second event handler get execute. The event object stops navigation. You can see the results when you click the inner child_mc in this example. You can only be able to see
=====================use capture true===================================
CAPTURING_PHASE
currenttarget: parent_mc
target: child_mc
If you uncomment that line then you will be able to see the events fired in bubbling phase also. So uncomment it and look at the results. You will see:
=====================use capture true===================================
CAPTURING_PHASE
currenttarget: parent_mc
target: child_mc
=====================use capture false===================================
BUBBLING_PHASE
currenttarget: parent_mc
target: child_mc
This tells us one good logic to control our events when we have to control the event flow while working with nested display objects.
Click here to download the example file.
Filed Under AS3, Flash | Leave a Comment »
keep looking »
