In my AIR application in Flex 4, I use mx:HTML, and when I navigate to a location like this
html.location = 'http://www.somesite.com';
But, some websites have "alert" function in javascript like this :
alert('hello world!');
and AIR show the message in a box...
I just want to remove, or ignore these messages, but I don't know how...
I think the solution is to extend the HTMLLoader class, but my experience in Flex is too poor..
Someone can help me ?
Thank in advance :)
This is the best thing I could find:
http://help.adobe.com/en_US/AIR/1.5/devappshtml/WS5b3ccc516d4fbf351e63e3d118666ade46-7e74.html#WS5b3ccc516d4fbf351e63e3d118666ade46-7e72
It looks like you can extend the HTMLLoader as you suggested and override javascript callbacks. I haven't tried this so I'm not sure but it's worth giving it a whirl.
After debug and test, I found that the HTMLLoader has a property window. This window is like javascript DOM window.
You can use following code to disable alert.
public class MyHTMLLoader extends HTMLLoader
{
override public function MyHTMLLoader()
{
super();
this.addEventListener(Event.HTML_DOM_INITIALIZE, htmlDomInitializedHandler);
}
protected function htmlDomInitializedHandler(event:Event):void
{
window.alert = function(){};
}
}
And modify your HTML component property htmlLoaderFactory to ...
<mx:HTML htmlLoaderFactory="{new ClassFactory(MyHTMLLoader)}" ...
Hope this will help you.
Related
I have the following AS code.I have noticed that if an Application i s using the webcamera then it cannot be used by any secondary applications until unless the primary application is closed.
My question is that from the following code 1.can we capture that condition
2.If no camera is detected how to give the alert since it is an AS code
EDIT:
Filename is cldAS.as
Now how to call cldAS() from any.mxml file .Some example would be appreciated
package org.com
{
import flash.display.Sprite;
import flash.media.*;
import flash.net.*;
public class cldAS extends Sprite
{
public function cldAS()
{
var cam:Camera = Camera.getCamera();
if(cam != null)
{
cam.setMode(640, 480, 30);
var video:Video = new Video(300, 450);
video.attachCamera(cam);
addChild(video);
}
else
{
trace("No Camera Detected");
//How to give an alert here
}
}
}
}
Alert.show("You don't seem to have a webcam.");
instead of
trace(...) ?
Alert is available in Flex only , in AS3 you should really implement your own solution, on the other hand , since Alert is a Javascript function , you could also use ExternalInterface to call it.
As far as implementing your own solution is concerned, at the minimum you need a TextField to display your message, which text you could provide by sending a CustomEvent with a message property that will simply take a String. It wouldn't take too much work to create your own Alert class.It would sit on top of your App , you could toggle visibility when receiving a CustomEvent and have a Close button to hide it.
You should be able to call your AS3 class within script tags , other than that I'll leave a more detailed answer to Flex experts. I'm not sure if you can add a Sprite directly into Flex , for all I remember an object in Flex must inherit from UIComponent in order to be added to the stage but check with the other guys here, I haven't used Flex in quite some time...
<mx:Script>
import org.com.cldAS;
public cld:cldAS = new cldAS();
</mx:Script>
I'm getting a Flex ArgumentError: Error #2025: The supplied DisplayObject must be a child of the caller.
This is what I've got:
a) I set the variable lastButtonClicked to the last button that was clicked in the main app.
private var lastButtonClicked:DisplayObject;
private function lastButtonClickedFunction(event:MouseEvent):void {
lastButtonClicked = event.currentTarget as DisplayObject;
}
b) I have a TitleWindow open and there is a yes/no option. I have a custom event return the answer to the main app.
c) In the main app, I'm trying to remove lastButtonClicked based on the data sent by the custom event. So, my problem is in this function. For some reason it won't let me remove the button. I get Error 2025 instead.
private function answerHandler( event:AnswerEvent ):void {
if(event.answerCorrect == true){
removeChild(lastButtonClicked);
}
}
Any suggestions on how to debug this problem? The custom event is firing okay. How do I fix this line: removeChild(lastButtonClicked); ?
Edit: I tried hbox1.removeChild(lastButtonClicked) and it worked. The proper button was removed from the main app. The problem is that not all of the buttons are in hBox1. I've got other HBoxes. So, I need to figure out a more generic way instead of using hBox1 in the statement. I tired this.removeChild(lastButtonClicked), but it didn't work. Thank you.
Thank you.
-Laxmidi
From what I understand, it seems like you have the buttons in a TitleWindow and the event handler in the application. You probably want to call removeChild for the instance of TitleWindow (eg: titleWindow.removeChild(lastButtonClicked) ) rather than from the application.
I solved it. I made a variable and set it to the parent of lastButtonClicked.
private var myParent:Object;
myParent = lastButtonClicked.parent;
Then in my answerHandler I wrote:
myParent.removeChild(lastButtonClicked);
Thank you.
-Laxmidi
Does anyone know what the onLoad() or similar Event is in Flex? I'm trying initialize, but no joy.
protected function videoArea_initializeHandler(event:FlexEvent):void
{
var currentPosition:int = videoArea.verticalScrollPosition;
if (currentPosition < 0)
{
left_button.visible = false;
right_button.visible = true;
}
}
The best alternative for onLoad() in Flex would be creationComplete.
See this link (Adobe) and this link (MikaFlex) for more information about the event hierarchy.
What are you trying to initialize? If you're asking for the Flex Parallel to OnLoad(); perhaps you should tell us where onLoad() comes from?
I strongly suggest reading up on the Flex Component LifeCycle.
You can do initalization in the constructor of a component. If using MXML, you might want to use the preinitialize event. Some folks also use creationComplete.
I have a flex app with lots of nested views and popup windows..
I'd love to catch all the CHANGE events in the application at the top level.. all of them, simply to notify the user that he has changed something (trust me it makes sense in my app).
Now, I tried to add an event listener in the Application creationComplete handler like this:
private function init():void {
this.addEventListener(flash.events.Event.CHANGE, function f():void {...})
}
but it does not work.. why? I read in the docs that event bubbling for the CHANGE event is set to false before dispatching. How can I change that? Is there any other way to achieve my goal?
thanks
Try listening to events on the SystemManager instead of the Application. As far as I understand, SystemManager sits at the very top of the display list, adding the application, popups and other UI entities as children.
In Flex 3 and below, you can retrieve it via Application.application.systemManager.
Read more on the SystemManager on Deepa's blog:
http://iamdeepa.com/blog/?p=11
I am also having trouble with a group of TextArea controls where I would like to listen for the change event on their container (parent) instead.
What I did in the end was to extend the TextArea class and create a listener for the change event. From the listener I would then dispatch a custom event that could bubble.
public class BubblingTextArea extends TextArea
{
public function BubblingTextArea()
{
super();
addEventListener(TextOperationEvent.CHANGE, changeHandler);
}
private function changeHandler(event:TextOperationEvent):void
{
dispatchEvent(new ChangeBubbleEvent(ChangeBubbleEvent.BUBBLE_CHANGE));
}
}
The custom event:
public class ChangeBubbleEvent extends Event
{
public static const BUBBLE_CHANGE:String = "bubbleChange";
public function ChangeBubbleEvent(type:String, bubbles:Boolean=true, cancelable:Boolean=false)
{
super(type, bubbles, cancelable);
}
}
I am sure someone can come up with a more elegant solution since I am still quite new to Flex and AS3 myself.
As far as I know, PopUps happen outside of the Application's main displayList, so that's probably why you're not seeing bubbling. In this case, you'll need to manually add listeners to popups. The Flash change event does bubble according to the docs: http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/events/Event.html#CHANGE
I personally like to use a framework such as RobotLegs or Parsley.
The basic idea is that each view and popup gets a mediator. The mediator's job is to communicate between the view and the command/model. Those mediators can listen directly to the view and the view's components.
in my flex application, I created a Tilelist. In this Tilelist, I am using an ItemRenderer to create a box consisting of an image and an VSlider in each tile.
The tile need to be dragable when you click on the image, but not dragable when you slide the slider. How can I achieve this ? I have been scratching my head searching on Google for one day and I have really no idea.
I look forward to your help.
Thank you.
I found a solution to my problem, however it may not be the best one.
Using this :
public var overImage:Boolean = false;
public function checkAllow(evt:DragEvent):void {
if(overImage == false)
{
evt.preventDefault()
}
}
public function isOverImage():void {
overImage = true;
}
public function isOutImage():void {
overImage = false;
}
I call those functions like this :
On my image component
mouseOver="outerDocument.isOverImage()" mouseOut="outerDocument.isOutImage()"
And for my tilelist I did this
Tiles.addEventListener(DragEvent.DRAG_START, checkAllow);
Hope it helps some people.
if(event.target is ScrollThumb )
{
return;
}
problem solved by returning the scrollThumb property of sroller in imageDragStart method...
BackGround:My TileList is provided with mouseDown ="event.currentTarget.addEventListener(MouseEvent.MOUSE_MOVE, imageDragStart )";
which was effecting complete TileList along with scroller ,
This above was the temp fix, but expecting experts suggestions.
Basically this is for Native application (AIR), used NativeDragStart. but am forced to use mouseDown over my TileList to invoke imageStartDrag() method of mine....