JavaFX 2.0 Stage onClose event

There is an event / handler to make some verification to confirm or not a stage close ?
There is onHiding() but this don´t cancel or block stage close.
Any idea ?
Regards,
Jean Paul Lopes

Couldn't find a way to keep the primary Stage open, but this is the closest I could get. See the documentation for Platform@runLater, particularly the guarantee that
The Runnables are executed in the order they are posted. A runnable passed into the runLater method will be executed before any Runnable passed into a subsequent call to runLater.
import javafx.application.Application;
import javafx.application.Platform;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.geometry.Pos;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.Label;
import javafx.scene.layout.FlowPane;
import javafx.scene.layout.VBox;
import javafx.stage.Modality;
import javafx.stage.Stage;
import javafx.stage.WindowEvent;
public class ConfirmClose extends Application {
  public static void main(String[] args) {
    Application.launch(args);
  @Override
  public void start(final Stage primaryStage) throws Exception {
    primaryStage.setOnHiding(new EventHandler<WindowEvent>() {
      @Override
      public void handle(WindowEvent event) {
        Platform.runLater(new Runnable() {
          @Override
          public void run() {
            primaryStage.setVisible(true);
        final Stage dialog = new Stage();
        dialog.initModality(Modality.APPLICATION_MODAL);
        Label label = new Label("Really exit?");
        Button okButton = new Button("OK");
        okButton.setOnAction(new EventHandler<ActionEvent>() {
          @Override
          public void handle(ActionEvent event) {
            dialog.hide();
            Platform.runLater(new Runnable() {
              @Override
              public void run() {
                primaryStage.setOnHiding(null);
                primaryStage.hide();
        Button cancelButton = new Button("Cancel");
        cancelButton.setOnAction(new EventHandler<ActionEvent>() {
          @Override
          public void handle(ActionEvent event) {
            dialog.hide();
        FlowPane pane = new FlowPane(10, 10);
        pane.setAlignment(Pos.CENTER);
        pane.getChildren().addAll(okButton, cancelButton);
        VBox vBox = new VBox(10);
        vBox.setAlignment(Pos.CENTER);
        vBox.getChildren().addAll(label, pane);
        Scene scene1 = new Scene(vBox);
        dialog.setScene(scene1);
        Platform.runLater(new Runnable() {
          @Override
          public void run() {
            dialog.initOwner(primaryStage);
            dialog.setVisible(true);
    primaryStage.setVisible(true);
}Debugging shows that the Stage is actually hidden when the setOnHiding's EventHandler's handle(...) returns. It also shows that, unlike in Swing, showing a modal dialog doesn't suspend the application thread.
db

Similar Messages

  • XMLSocket onClose event is unreliable

    I use XMLSocket in my application and I have connection
    management code that automatically reconnects if onClose is called.
    However, I've found that often (especially if the connection is
    open for a long time) the onClose event isn't called. What causes
    onClose to be called? Is there anyway to do one of the following:
    - Reconnect in such a way that nothing will happen if I'm
    already connected? (Just calling .connect again seems to
    disconnect/reconnect me, which is not what I want)
    - Check to see if the XMLSocket is connnected?
    - More reliably receive onClose events?

    Hi David,
    Yes, my apologies, I am referring to a dockable panel.  I did see this thread which I thought was referring to a dockable panel as well. 
    http://forums.adobe.com/message/6181054#6181054
    I’m trying to save to the preferences file when the user closes the panel in CC.  Is this just not possible with a dockable panel?  If not, what do you think is a good work around for saving preferences.
    Thanks,
    Arie

  • Handle stage RESIZE.Event

    I've a flash site 100x100% in browser window.
    When I open new tab in browser window Event.RESIZE doesn't
    dispatched.
    Have any idea how to handle this event except EnterFrame or
    Timer listeners?

    stage.scaleMode = StageScaleMode.NO_SCALE;
    var count = 0;
    stage.addEventListener(Event.RESIZE, resizeHandler);
    function resizeHandler(evt:Event):void {
    _txt.text = count++;
    use this code

  • Stage mouse events

    Hi everybody,
    i need a simple method to check if the mouse left the
    application and when i comes back in.
    i tried
    private function
    creationCompleteHandler(event:FlexEvent):void
    this.addEventListener(MouseEvent.MOUSE_OUT,
    mouseOutHandler);
    this.addEventListener(MouseEvent.MOUSE_OVER,
    mouseOverHandler);
    but these events ALSO fire when i move the mouse onto a
    button that is added to the stage (without leaving the stage).
    another thing is how can i check a drag of a object to the
    outside of the swf?
    in AS2 there is a event "releaseOutside" that does the job,
    is there something similar in Flex2 aswell?
    What's this all about? I embedded this flash inside a C++
    application and want to do some drag and drop interaction and
    communication of flash and c++ via
    flash.external.ExternalInterface.
    So i must know when something is currently dragged and then
    the mouse left the flash.
    When i release the mouse outside the flash inside the c++ app
    the mouseUp event does not fire of course, thats the other problem.
    Hope I made myself clear and someone can help.
    Best regards,
    Dzihan

    Flash 9 plugin does support full screen so that might be one
    solution.
    There is a Mouse_Leave event in AS3 that can tell you when
    the mouse leaves the area of your swf. You would then need to use
    externalinterface to communicate with some technology outside of
    flash such as javascript or such. I wouldn't know how to do it.
    Other than the full screen approach it all seems like a lot
    of trouble. Without knowing the exact specifics of what you are
    making can't you just have some kind of symbol that indicates the
    direction you are going and if they leave the stage area it either
    keeps going in the last direction or it returns to center until the
    mouse comes back?

  • How to remove event listener when all the MoviClip are off the stage

    Hi i am newbie to as3,
        I am creating animation using as3 in which i duplicate the circle ten time,then pushing into an array and giving random motion. When all the duplicate object goes outside the stage then i should remove the event listener. But right now when one duplicate object goes off the stage the event listener is removed. Thanks in advance

    //---------code for creating random bubble movement------//
    var bubbleNo:Number = 10;
    var vx:Number = .3;
    var vy:Number = .5;
    var bubbles:Array = new Array();
    var bubbleRadius:Number = 9;
    var myColor:ColorTransform = this.transform.colorTransform;
    init();
    function init():void {
    for(var i:Number = 0; i<bubbleNo; i++){
              var bubble = new newBall();
    bubble.x = Math.random() * stage.stageWidth;
    bubble.y = Math.random() * stage.stageHeight;
    //bubble.color = Math.random
    //trace("bubble.x=="+bubble.x+"bubble.y=="+bubble.y);
    bubbles.push(bubble);
    myColor.color = Math.random() * 0xFFFFFF
    bubble.transform.colorTransform = myColor;
    addChild(bubble);
              addEventListener(Event.ENTER_FRAME,createBubble);
    //addEventListener(Event.ENTER_FRAME,createBubble);
    function createBubble(event:Event):void{
    for(var k:Number = bubbles.length-1; k>0; k--){
              var bubble = (newBall)(bubbles[k]);
              bubble.x += vx;
              bubble.y += vy;
              if(bubble.x - 18 > stage.stageWidth || bubble.x + 18 < 0  || bubble.y - 18 > stage.stageHeight || bubble.y + 18 < 0){
                        removeChild(bubble);
                        bubbles.splice(k, 1);
                        //trace("out"+bubbles.length);
                        if(bubbles.length <= 0 );
                                  removeBubble();
                                  trace(bubbles.length);
                                  //removeEventListener(Event.ENTER_FRAME,createBubble)
                        trace("all Bubbles cleared");
                        function removeBubble():void{
                                  removeEventListener(Event.ENTER_FRAME,createBubble)

  • Order of elements and events.

    INTRO
    Hi Oracle community.
    A while ago I started a thread here on the forum where I had put three different subjects to be treated. The user jsmith guided me saying that I was supposed to separate things, dividing each subject in a separate thread. The original discussion is at the following link:
    Interesting things, however, unknown? StackPane, animations and filters.
    ABOUT
    So in this discussion, I will be talking about input events and maybe about event filters. I created a JavaFX 8 (b123) application that checks the mouse click on certain nodes. Basically I have a panel of buttons. Behind this panel, I have a scroll pane with rectangles. The rectangles are contained within a Group, and the buttons are in a VBox. The Group is set as ScrollPane content. VBox and ScrollPane are within a StackPane, which becomes the root of scene graph. If we observe the nodes tree, we'll find the following scenario:
    IMAGE
    Here is my source code:
    import javafx.application.Application;
    import javafx.event.EventHandler;
    import javafx.geometry.Pos;
    import javafx.scene.Group;
    import javafx.scene.Scene;
    import javafx.scene.control.Button;
    import javafx.scene.control.ScrollPane;
    import javafx.scene.input.MouseEvent;
    import javafx.scene.layout.StackPane;
    import javafx.scene.layout.VBox;
    import javafx.scene.paint.Color;
    import javafx.scene.shape.Rectangle;
    import javafx.stage.Stage;
    public class ScrollTest extends Application
        //                                                                                                       MAIN
        public static void main(String[] args)
            Application.launch(args);
        //                                                                                                 INSTÂNCIAS
        // CONTROLS
        private Rectangle[] rectangles;
        private ScrollPane scrollP;
        private Button[] buttons;
        // LAYOUTS
        private StackPane root;
        private Group group;
        private VBox vbox;
        //                                                                                                  INÍCIO FX
        @Override public void start(Stage estagio) throws Exception
            this.iniFX();
            this.confFX();
            this.adFX();
            this.evFX();
            Scene cenario = new Scene(this.root , 640, 480);
            estagio.setScene(cenario);
            estagio.setTitle("Programa JavaFX - RDS");
            estagio.show();
        /** Just instantiate JavaFX objects.*/
        protected void iniFX()
            // CONTROLS
            this.rectangles = new Rectangle[5];
            this.scrollP = new ScrollPane();
            this.buttons = new Button[6];
            // LAYOUTS
            this.root = new StackPane();
            this.group = new Group();
            this.vbox = new VBox();
        /** Just sets the JavaFX objects.*/
        protected void confFX()
            // CONTROLS
            for(int count = 0 ; count < this.rectangles.length ; count++)
                this.rectangles[count] = new Rectangle();
                this.rectangles[count].setWidth(Math.random() * 100 + 20);
                this.rectangles[count].setHeight(Math.random() * 100 + 20);
                this.rectangles[count].setFill(Color.rgb((int) (Math.random() * 255) , (int) (Math.random() * 255) , (int) (Math.random() * 255)));
                this.rectangles[count].setTranslateX(Math.random() * 600);
                this.rectangles[count].setTranslateY(Math.random() * 600);
                this.rectangles[count].setRotate(Math.random() * 360);
            for(int count = 0 ; count < this.buttons.length ; count++)
                this.buttons[count] = new Button("Button - " + count);
            // this.scrollP.setVbarPolicy(ScrollBarPolicy.ALWAYS);
            // this.scrollP.setHbarPolicy(ScrollBarPolicy.ALWAYS);
            this.scrollP.setPrefSize(400 , 400);
            // LAYOUTS
            this.vbox.setAlignment(Pos.CENTER);
            this.vbox.setSpacing(20);
            // This doesn't solve my problem.
            // this.vbox.setMouseTransparent(true);
        /** Just create the realtion between nodes, and the root.*/
        protected void adFX()
            for(int count = 0 ; count < this.rectangles.length ; count++)
                this.group.getChildren().add(this.rectangles[count]);
            for(int count = 0 ; count < this.buttons.length ; count++)
                this.vbox.getChildren().add(this.buttons[count]);
            this.scrollP.setContent(this.group);
            this.root.getChildren().add(this.scrollP);
            this.root.getChildren().add(this.vbox);
        /** Just add some events to some nodes for debugging.*/
        protected void evFX()
            this.vbox.setOnMousePressed(new EventHandler<MouseEvent>()
                @Override public void handle(MouseEvent e)
                    System.out.println("Mouse pressed inside VBox.");
            this.scrollP.setOnMousePressed(new EventHandler<MouseEvent>()
                @Override public void handle(MouseEvent e)
                    System.out.println("Mouse pressed inside ScrollPane.");
            if(this.rectangles.length > 0)
                this.rectangles[0].setOnMousePressed(new EventHandler<MouseEvent>()
                    @Override public void handle(MouseEvent e)
                        System.out.println("Rectangle pressed.");
                        rectangles[0].setFill(Color.rgb((int) (Math.random() * 255) , (int) (Math.random() * 255) , (int) (Math.random() * 255)));
    THE PROBLEM
    I wish I could click the mouse on VBox buttons, but also in the scroll pane, and in it's internal contents (the rectangles). I tried changing the VBox mouseTransparent property to true, and modify mouseTransparent to false on each VBox button, but that did not work. I've been reading the JavaFX documentation talking about routing events, and found the following:
    The route can be modified as event filters and event handlers along the route process the event. Also, if an event filter or event handler consumes the event at any point, some nodes on the initial route might not receive the event.
    Could it be that VBox is filtering events so they do not reach ScrollPane? Or is this being done by StackPane in some other manner? Does anyone have any idea what I could do?
    In any case, I thank you for your attention.

    You might need to modify the event dispatch tree so that the events get beyond the VBox. I'm not saying this is the right thing to do, but something worth looking at.
    root.setEventDispatcher(new EventDispatcher() {
    @Override
    public Event dispatchEvent(Event event, EventDispatchChain tail) {
    tail.append(group.getEventDispatcher());
    return tail.dispatchEvent(event);
    There is some info on event processing at Handling JavaFX Events: Processing Events | JavaFX 2 Tutorials and Documentation

  • Re: Is this a bug in onClose?

    The problem is that we have no way to prevent JavaFX of really closing a stage.
    I don't know why the stage re-appears after the first close. But I guess the onClose isn't called anymore because JavaFX thinks the stage is already closed.
    Or something like that...
    Actually, I don't see why you just hide the dialog. It might be better to let it close and re-create it each time.
    class DateAndTimePicker extends CustomNode {
         override function create(): Node {
            return controls;
        public-read var validatedOK=false;
        public-read var date="  /  /  ";
        public-read var time="  :  :  : ";
        public var title = "Date & Time";
        var controls = HBox {
            content: [
                Label {
                    text: bind title
                TextBox {
                    text: date.concat(time)
                    columns: 18
                    selectOnFocus: true
                Button {
                    text: ">"
                    action: function() {
                            println("about to open");
                            println("title is {title}");
                            displayPopup();
                            println("opening");
        function displayPopup(): Void {
            Stage {
                title: bind title
                visible: true;
                resizable: false
                onClose: function() {
                    println("closing");
                scene: Scene {
                    content: [
                        Button {text: "Button with some really, really long text"}
    }

    What did the mackerel do to deserve that?it wrote Sun's search function !!!!!! :pPlease, a mackerel would of done a better job.
    All I can say is "JTable project", smiles.
    (Gah, Please kill me)mlk BANG BANG*
    *Post decease operator.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               

  • Rendering in JavaFX

    Hi,
    I am currently working on my bachelor thesis about JavaFX 2
    I have a few questions about rendering in JavaFX
    I don’t really understand what the glass toolkit is for and how it’s connected to prism.
    If the glass toolkit is firing the pulse event how does prism know that it has to render a frame?
    And how does the Quantum Toolkit handling the threads?
    And what is the advantage of having two threads (Application and Prism Render Thread) instead of one like in Swing?
    I haven’t found much about rendering in the documentation so please help me. :)

    Hi David,
    Glass is to FX as AWT is to JavaSE. Sort of :-). Glass is our windowing toolkit implementation. It is responsible for showing windows (including Stage, Popup, etc), managing the event queue, passing events up to JavaFX, and setting up timers. Every native application (on Windows, Mac, Linux, etc) has a native event queue. On some platforms like Mac, you get callbacks called whenever an event needs to be handled (that is, the native system pumps the event queue and delivers events to native callback methods). So on Mac Glass, we get these native callbacks, turn them in to JavaFX events, and send them to JavaFX (more or less). On Windows we have to manually pump the event queue, pulling off the event, creating the JavaFX event equivalent, and then pass that up to JavaFX for dispatching.
    Pulse events are normal events on our event queue, but they are generated based on a timer. Glass sets up a timer which fires off every 16.666ms. It is either based on just a hi resolution system timer (native), or it is based on a callback from the OS whenever the video card refresh occurs. This latter mechanism is much more precise, system timers can sometimes drift leading to "jitter" in animations whereas the video card refresh is pretty rock solid. When JavaFX gets notified by glass when the timer fires, it checks to see: is there a pulse already queued up or being handled? If so, don't fire another pulse (keeps us from flooding the event queue with pulses). If the scene is not dirty and there are no animations, then we don't need to handle the pulse. Otherwise if the scene is clean but there are animations, then we handle the pulse. A PulseEvent is then created and put on the event queue.
    During the normal process of handling the events on the event queue, when we encounter a pulse event, we then do the following things:
    - Process animations
    - Process CSS
    - Process Layout
    - Synchronize from the FX scene graph to the render tree (Prism)
    - Pick the scene and update the mouse hover state if a node has moved under the cursor or moved out from under the cursor
    The render thread then goes off and renders after the synchronization step has occurred.
    Quantum is the thing that listens to Glass pulse timer events and creates the PulseEvent and adds it to the event queue, and is also the thing that handles the pulse event, causing animations to be processed and then telling each scene to handle the pulse event (where each scene processes CSS, layout, and synchronizes etc). Quantum then tells the render thread to go off and render.
    Presently in JavaFX, although we have a render thread and application thread, they both essentially run synchronous. I have a patch going into 3.0 as soon as the repo opens that allows us to run multithreaded, where the FX app thread and render thread will be running in parallel except for the brief period of time where they synchronize during the pulse. We have seen 1.5x - 2x performance improvement on tablets by running these threads in parallel. We've also noticed 40%+ performance improvement on desktop in some of the scenarios I've run thus far. Having multiple threads just makes sense in a world where we have multiple cores (even on embedded systems!). Even on a single core, multiple threads might still be advantageous because the CPU doesn't have to wait on memory read operations or GPU operations but can be busy computing the state for the next rendered frame. Having multiple threads does increase the memory overhead, but actually it may not do so very significantly (we have one prototype where we found that the performance cost in constantly converting from FX Color to native Color objects was so bad that caching the converted color object was cheaper anyway, so it isn't clear that even in an immediate-mode style single-threaded rendering system that you'd save much in terms of memory).
    I don't know when your thesis is due by, unfortunately a lot of code in this area hasn't been open sourced yet so you're kind of flying blind. May the decompiler ever guide you ;-)

  • Drag event handling in JFXPanel has performance implications with expensive event handlers

    We have a drag event handler that is a little expensive, takes something like 20ms. The respective code must be run in a synchronous manner however.
    That is no problem in a pure JavaFX environment, as less drag events are created when CPU load is high.
    However, when embedded into Swing using JFXPanel this adaptation doesn't kick in, lots of drag events are created and the application becomes sluggish.
    Is there a way to mimic what JavaFX does in the JFXPanel scenario?
    The code below is a self-contained example that demonstrates what I'm describing.
    Some results I had:
    -eventHandlerSleep=5 -noswing --> 128 drag events
    -eventHandlerSleep=30 -noswing --> 46 drag events
    -eventHandlerSleep=5  --> 136 drag events
    -eventHandlerSleep=30  --> 135 drag events
    {code}import java.util.Arrays;
    import javax.swing.*;
    import com.sun.glass.ui.Robot;
    import javafx.application.Application;
    import javafx.application.Platform;
    import javafx.embed.swing.JFXPanel;
    import javafx.event.EventHandler;
    import javafx.scene.Scene;
    import javafx.scene.input.MouseEvent;
    import javafx.scene.layout.BorderPane;
    import javafx.stage.Stage;
    public class DragHandlingTester {
        private static long EVENT_HANDLER_SLEEP = 30;
        public static void main(String[] args) {
            for (String arg : args) {
                if (arg.startsWith("-eventHandlerSleep=")) {
                    EVENT_HANDLER_SLEEP = Long.parseLong(arg.split("=")[1]);
            if (Arrays.asList(args).contains("-noswing")) {
                Application.launch(JavaFXDragHandlingTestApp.class, args);
            } else {
                new SwingDragHandlingTestApp();
        static class SwingDragHandlingTestApp {
            SwingDragHandlingTestApp() {
                JFrame frame = new JFrame();
                final JFXPanel fxMainPanel = new JFXPanel();
                Platform.runLater(new Runnable() {
                    @Override
                    public void run() {
                        DragTestScene dragTestScene = new DragTestScene();
                        fxMainPanel.setScene(dragTestScene.createScene());
                frame.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
                frame.getContentPane().add(fxMainPanel);
                frame.setSize(800, 600);
                frame.setVisible(true);
        public static class JavaFXDragHandlingTestApp extends Application {
            @Override
            public void start(Stage primaryStage) {
                primaryStage.setWidth(800);
                primaryStage.setHeight(600);
                primaryStage.setX(0.0);
                primaryStage.setY(0.0);
                DragTestScene dragTestScene = new DragTestScene();
                primaryStage.setScene(dragTestScene.createScene());
                primaryStage.show();
        static class DragTestScene {
            private int drags = 0;
            public Scene createScene() {
                new Thread(new Runnable() {
                    @Override
                    public void run() {
                        try {
                            // after 1 second drag mouse across window
                            Thread.sleep(1000);
                            Robot robot = com.sun.glass.ui.Application.GetApplication().createRobot();
                            robot.mouseMove(50, 50);
                            robot.mousePress(1);
                            for (int i = 20; i &lt; 700; i = i + 5) {
                                robot.mouseMove(i, 50);
                                Thread.sleep(10);
                            robot.mouseRelease(1);
                        } catch (Exception e) {
                            e.printStackTrace();
                }).start();
                BorderPane borderPane = new BorderPane();
                borderPane.setOnMouseDragged(new EventHandler() {
                    @Override
                    public void handle(MouseEvent mouseEvent) {
                        drags++;
                        try {
                            Thread.sleep(EVENT_HANDLER_SLEEP);
                        } catch (InterruptedException ignored) {
                        System.out.println("Number of drag events: " + drags);
                return new Scene(borderPane);
    {code}

    Ok, I expected something like this to be the reason. We'll probably have to live with it.
    My workaround right now is to use background tasks with an executor that has a single element queue handling the events in order, but rejecting any additional events as long as there is a queued event.
    Still not the same performance as in JavaFX, but at least it's usable now.

  • Reaching a movie on the stage from inside another movie clip

    I'm trying to reach a body of text which i turned into a movie clip which is on the main stage, and have it scroll up/down whenever it rolls over the designated hot spots. Here's what i have.
    stage.addEventListener(MouseEvent.MOUSE_MOVE,down1,false,0,true);
    function down1(e:MouseEvent):void {
         if (mouseX>=0 && mouseX<=42 && mouseY>111.1 && mouseY<146.1) {
              stage.addEventListener(Event.ENTER_FRAME,scrolldown1);
         } else {
              stage.removeEventListener(Event.ENTER_FRAME, scrolldown1);
    function scrolldown1(e:Event):void {
         if(MovieClip(this.root).resume_txt.y > 219) {
              MovieClip(this.root).resume_txt.y += 5;
         } else {
              this.removeEventListener(Event.ENTER_FRAME, scrolldown1);

    Can you explain the purpose bhind these lines...
         if(MovieClip(this.root).resume_txt.y > 219) {
              MovieClip(this.root).resume_txt.y += 5;
    It seems as though if it is >219, it will move until the mouse moves out of the region.  Is there any specific aspect of it that you can pinpoint as not woking?.

  • Stage Height/Width Issue

    I am writing a piece of code that basically says if a certain MC reaches a ypos of -50 to perform a set of actions:
    EXAMPLE CODE
    if(balloon.clip.y <= topBounds)
                    //actions here
    But for some reason it wasn't recognizing when the MC would reach the specified ypos. I did a simple trace statement of the stage height and width because I suspected something was off with the script reading x and y positions. And sure enough the output of the trace did not correctly match what my actual stage size was set to in my fla.
    trace(stage.stageHeight); This traced 798
    trace(stage.stageWidth); This traced 1440
    While my actual stage is set to 550x400.
    Am I missing something here? I also traced the ypos of the moving MC and the trace output positions that were nowhere near the actual y positions of the MC as it moved. Ironically though, the external class file to this object recognizes the correct x and y positions when I call the function from the .as file. Only when I try to call the function from the fla file do I run into this issue of incorrect x and y positions.
    Any help? Thanks

    Below is my code for my as class file and the code being called from the stage within the fla file. The issue I am having is with the conditional statement in the fla code, I have highlighted it in bold and italics. The ypos of the MC is not registering at -50 when clearly the object has a y position of -50. Something seems messed up with the x and y positions of the clip on the stage because the y position traced to teh output panel is nowhere close to the actual y position of the clip on the stage as it moves.
    .as file code
    package
        import flash.display.Stage;
        import flash.display.*;
        import flash.display.DisplayObjectContainer;
         import flash.display.MovieClip;   
        import flash.utils.Timer;
        import flash.events.TimerEvent;
        import flash.events.Event;
            public class Balloon
                    public var clip: MovieClip;
                    public var xVel: Number = 0;
                    public var yVel: Number = 0;
                    public var upwardForce:    Number = 0; // applies to y value
                    public var shrink: Number = 1;
                    public var fade: Number = 0;
                    public var topBounds: Number = -50
                    public function Balloon(symbol:Class, target:DisplayObjectContainer, xpos:Number, ypos:Number, size:Number)
                            clip=new symbol();
                            target.addChild(clip);
                            clip.x = xpos;
                            clip.y = ypos;
                            clip.scaleX=clip.scaleY=size;
                        } // end Balloon constructor function
                    public function moveObject():void
                            clip.x += xVel;
                            clip.y += yVel;
                            yVel -= upwardForce;
                            clip.scaleX *= shrink;
                            clip.scaleY *= shrink;
                            clip.alpha -= fade;
                      }//end moveObject function
                    public function removeObject():void
                            clip.parent.removeChild(clip);
                        }// remove balloon from the stage
                } // end Balloon class
    }// end package
    code inside fla
    var balloonArray:Array = new Array();
    stage.addEventListener(Event.ENTER_FRAME, startBalloons)
    function startBalloons(evt:Event):void
            var balloon: Balloon; // referencing our Balloon Class
            for(var i:int=0; i<balloonArray.length; i++)
                    balloonArray[i].moveObject(); // calls moveObject function thats in the class file
            balloon = new Balloon(hotAirBalloon, this, randomRange(200, 400), randomRange(400, 550), randomRange(0.3, 1));
            balloon.xVel = -3; 
            balloon.yVel = -4;
            balloon.shrink = 0.9999;
            balloon.fade = 0.000011;
            balloon.upwardForce = .005
            balloonArray.push(balloon);
            if(balloonArray.length>randomRange(1, 5))//creates only 3 balloons and removes all others created from th array
                   balloon.removeObject();
        if(balloon.clip.y <= -50)
           trace("balloon has reached the top"
            var balloonTimer:Timer = new Timer(randomRange(25,45)*1000, 1);
            balloonTimer.addEventListener(TimerEvent.TIMER,timerFinished);
            balloonTimer.start();
            function timerFinished(event:TimerEvent):void
                        trace("time's up")
                        balloonTimer.stop();
                        balloon.clip.x = Math.random() * (400-200) + 200; // give random x pos to start from
                        balloon.clip.y = Math.random() * (1000-400) + 400; // give random y pos to start from
                        balloon.clip.scaleX = balloon.clip.scaleY = Math.random() * (1-0.3) + 0.3;
                        balloon.clip.alpha=1;
            } // end startBalloons function
        function randomRange(offset:Number, maxValue:Number) // generic function for randomizing object properties
                return Math.random() * (maxValue-offset) + offset

  • [JS/CS4/CS5] Catching a selection event in a ScriptUI interface.

    I've got this ScriptUI interface (javascript based), and now I wonder if it would be possible to change one of its button captions depending on whether anything is selected or not, in the active document (would also have to be updated if the user selects or opens another document).
    1. Is it possible to write event listeners for this?
    2. Would it be possible to include this in the same script as the rest of the Script UI interface code (that is, I'd prefer avoiding a separate file in the startup folder).
    3. What's the best source of information regarding events, which ones there are, and how to handle them in javascript?
    Andreas

    1. Yes. The selection events work well in my experience.
    2. Yes, you don't have to add them at startup. You can do something like:
    app.addEventListener("afterSelectionChanged", selectionChangedFunction);
    before you open your window. Remove the listener in the onClose event of the window. I think you'll have to have some error trapping in the selectionChangedFunction to deal with app.selection erroring after a document close or during a revert.
    3. See this thread for an extension that lets you see events as they're happening.
    Jeff

  • Call function in external .js from stage.onCompletion

    I have my edge composition, and some functions in sim.js
    within the stage.onCompletion event, I have:
    $("<script type='text/javascript' src='sim.js'></script>").appendTo("#Stage");
    how can I call functions, e.g. "testMe()" that are in sim.js from within the stage.onCompletion event?
    $("testMe()"); was my first thought, but no. what am I missing?

    Lloydie maybe you can help me with this similar problem here (i think it is similar)
    I am uncertain that i can use "transform" in edge, transform belongs to jquery.transform.js library. I am particulalry interested in animate({transform:.... to animate rotation and scales.
    Can I call the transform.js into the stage like the way you called your custom .js?
    Can we import additional libraries ?

  • How to detect the HTML extension window close in In-design? Does the In-design throws any event on opening/closing of extensions?

    How to detect the HTML extension window close in In-design? Does the In-design throws any event on opening/closing of extensions?
    I have a HTML extension running in In-design CC 2014 version.
    I want to perform some required set of actions before my extension window is closed(by clicking on the cross button on top right corner).
    Does In-design throws any event for it? Or can we capture it using C++ plugin in some way?

    Naah.......haven't got any event for that yet.
    Although, since HTML extensions are using chromium browser,  as a workaround, u can attach listener to HTML onClose event, but it won't solve any purpose if you
    are looking to logout session or do some business login in your code.

  • REMOVED_FROM_STAGE event firing when it shouldn't...

    Hello everyone,
    Wondering if someone has seen this before. I have an application that has a few navigation points on the main timeline. The document class stops the movie at the first frame, and the "home" movieclip's class has Event.ADDED_TO_STAGE and Event.REMOVED_FROM_STAGE listeners on it. Funny thing is, it is calling the ADDED function as normal, then firing the REMOVED function immediately after. However, when I run it, it doesn't actually remove the movieclip from the stage. It is still there. When I navigate to a different section ("remote" or "assist") and navigate back to "home", it doesn't fire a second time, everything works properly after the first time.
    So I guess my question is, what would fire the REMOVED_FROM_STAGE event without actually removing the object from the stage? And why would it only happen once?
    Thanks for looking!
    -Nick
    Here is some code as well as a screen shot of my main timeline:
    package src.modules {
        import flash.display.MovieClip;
        import flash.events.Event;
        import flash.events.MouseEvent;
        import src.utils.greensock.TweenLite;
        import src.utils.greensock.easing.*;
        public class ModHome extends MovieClip {
            private static const DISTANCE:int = 700;
            private static const TWEEN_DURATION:Number = 1.0;
            private var _currentPage:int = 1;
            private var _isDone:Boolean = true;
            public function ModHome() {
                super();
    //            trace("home initialized");
                addEventListener(Event.ADDED_TO_STAGE, onAddedToStage, false, 0, true);
            private function onAddedToStage(evt:Event):void {
                trace("home added to stage");
                removeEventListener(Event.ADDED_TO_STAGE, onAddedToStage);
                addEventListener(Event.REMOVED_FROM_STAGE, onRemovedFromStage, false, 0, true);
                // BUTTONS
                pageLeft_btn.addEventListener(MouseEvent.CLICK, onMouseClick, false, 0, true);
                pageRight_btn.addEventListener(MouseEvent.CLICK, onMouseClick, false, 0, true);
            private function onRemovedFromStage(evt:Event):void {
                removeEventListener(Event.REMOVED_FROM_STAGE, onRemovedFromStage);
                // BUTTONS
                pageLeft_btn.removeEventListener(MouseEvent.CLICK, onMouseClick);
                pageRight_btn.removeEventListener(MouseEvent.CLICK, onMouseClick);
    //            trace("home removed from stage");
            private function onMouseClick(evt:MouseEvent):void {
                if(_isDone) {
                    switch (evt.target.name) {
                        case "pageLeft_btn" :
                            movePages("left");
                            break;
                        case "pageRight_btn" :
                            movePages("right");
                            break;
                        default :
    //                        trace("home -- nothing");
                            break;
            // SCROLLING WINDOW
            private function movePages(thedirection:String):void {
                _isDone = false;
                var x1:int;
                switch (thedirection) {
                    case "right" :
                        if (_currentPage > 1) {
                            _currentPage = _currentPage - 1;
                            x1 = pages_mc.x + DISTANCE;
                            TweenLite.to(pages_mc, TWEEN_DURATION, {x:x1, ease:Quint.easeInOut, onComplete:onTweenComplete});
                        } else {
                            _isDone = true;
                        break;
                    case "left" :
                        if (_currentPage < 3) {
                            _currentPage = _currentPage + 1;
                            x1 = pages_mc.x - DISTANCE;
                            TweenLite.to(pages_mc, TWEEN_DURATION, {x:x1, ease:Quint.easeInOut, onComplete:onTweenComplete});
                        } else {
                            _isDone = true;
                        break;                   
            private function onTweenComplete():void {
                _isDone = true;
                pageMarker_mc.gotoAndStop(_currentPage);
    //            trace("complete");

    No reason in particular, when I created the class, FlashBuilder put it in there (I'm using Flash Pro CS5 + Flash Builder 4). I read that it calls it by default when the class is constructed, so having it in or out didn't really matter. I did comment it out with no luck, but I ended up shifting around the timeline quite a bit today and the problem has gone away. It seemed to only do it when it was in the first frame.
    Thanks for your help, I'm going to investigate it further when I have time just for reference, I'll post anything I find here.
    -Nick

Maybe you are looking for

  • How do I connect a second Cinema Display to a Radeon 9600 PRO card?

    I have a G5 dual (PowerMac7,2) with a Radeon 9600 pro card running an HD cinema display (clear plastic) and want to connect a second smaller 20" Cinema Display with the same type of plug - I think I need a DVI to ADC adapter - is this the case? Thank

  • Unable to read tabfile containing char u00E9 (spanish)from appln server in 4.7

    Hello, I am facing a problem during read of a tab delimited file from application servers. My file contains spanish and japanese text(eg. éêèóñôçëíáÉÓÍÚÁ), when i upload the file onto application server and perform read using the following code, all

  • Display Resolution Question

    New to iMac.  Running 27in and monitor resolution set at "Best for Display 2560X1440".  Having problem getting Web pages to display properly.  At this resolution, page display is not good.  Spacing is not correct to see all information.  Changed reso

  • How to Install deskjet3510 on iPad

    How do I install hp desk jet 3511 all-in-one on my iPad

  • De-selection in a DataGrid

    I use a DataGrid in a popup window. When it is shown in the first-time, no rows are selected. A row gets selected when using the data grid. Then the Popup DataGrid will be closed. When I open the popup window again, the previous selection is still th