AS3 - Problem sending

I have a Flash AS3 project that loads and manages external SWFs in different ways. Some of the downloaded SWF files have a Next Select button that takes you to a new presentation. On my main external loaded SWF, I have the code:

setTimeout(function() {dispatchEvent(new Event("nextPresentation", false));}, 4000);

      

Which automatically go to the next selection in the set. This code works exactly the way I want.

In the next SWF loaded, instead of having a timeout, the user looks at everything that there is a button at the end of all time frames that says next choice. So I added the following code there:

function nextSelectionClick(evt:MouseEvent) {
    trace('here123');
    dispatchEvent(new Event("nextPresentation", false));
} 

      

For some reason, this event never gets to the file loading the SWF. I'm sure I'm getting to the click event because I get a traceback but the event never ends, although it seems like it should be the same behavior as the timeout. What am I missing here? Why would this code be different from a button click than a timeout?

thanks

0


a source to share


3 answers


You are correct that they should work the same way, which leaves a giant question of what else is going on in the application. It seems though the problem isn't here, but somewhere else.

I hate to ask a question like this, but are you sure the event is being fired from the root display object? If you don't shoot from there, you won't hear him outside.



Sorry, but I can't give you more without seeing more current code or learning more about the situation.

Tyler.

+3


a source


I think you have set the attribute bubbles

to false

. This will prevent bubbles from exceeding the container it is in.

Try this instead:



dispatchEvent(new Event("nextPresentation", true));

      

Also, as far as organization is concerned, I would make a class PresentationEvent

and have event constants SKIP_PREVIOUS

and on it SKIP_NEXT

. This is more consistent with the event model that ActionScript uses and reduces redundancy. This way, you can pass the current presentation and other useful presentation-related data as part of the event.

+1


a source


I also use a custom dispatch event, but sometimes it works and sometimes it doesn't. For instance:

private function rollBackAction
{
  var atd:Class =  getDefinitionByName("com.utils."+CreateList.currentClass) as Class;
  dispatchEvent(new AppEvent("RollBackAction",{}));

}

      

and the function used

package com.utils
{

import com.components.mouseOverAct;
import com.model.CreateList;
import com.SequenceCheck.SeqCheck;
import com.events.AppEvent;


import flash.display.MovieClip;

import flash.events.MouseEvent;

import flash.events.Event;


public class RightRotate extends mouseOverAct
{
    private var rotateBool:Boolean;
    private var XposIntial:Number;
    private var A:Number;
    private var An:Number;
    private var angle:Number;
    var mc:MovieClip;
    private var frameCount:int;

    public function RightRotate()
    {
        trace("main")
        this.buttonMode = true;
        this.addEventListener("RollBackAction",rollingBack);
        knob_mc.addEventListener(MouseEvent.MOUSE_DOWN,turn);
    }
    private function rollingBack(e:AppEvent)
    {
        trace("Abc")
        knob_mc.rotation = An;
        rotation_01.gotoAndStop(A);
    }
    private function turn(e:MouseEvent):void
    {
        mc = simulator.activityAssets.spw.neddle;
        CreateList.excerciseName = "Right_Bottom_Right";
        CreateList.currentClass = "RightRotate";
        A = rotation_01.currentFrame;
        An = knob_mc.rotation;
        this.stage.addEventListener(MouseEvent.MOUSE_MOVE,turn);
        this.stage.addEventListener(MouseEvent.MOUSE_UP,endTurn);
        var position:Number = Math.atan2((mouseY - knob_mc.y),mouseX - knob_mc.x);
        //trace(position);
        angle = (position / Math.PI) * 180;
        knob_mc.rotation = angle;
        if (CreateList.stepId >= 3)
        {
            if (mc.currentFrame > 3)
            {
                mc.gotoAndStop(mc.currentFrame + 5);

            }
        }
        mainProcess();
    }

    private function endTurn(e:MouseEvent):void
    {
        rotateBool = false;
        rotation_01.gotoAndStop(rotation_01.currentFrame);
        knob_mc.removeEventListener(MouseEvent.MOUSE_DOWN,turn);
        this.stage.removeEventListener(MouseEvent.MOUSE_MOVE,turn);
        knob_mc.addEventListener(MouseEvent.MOUSE_DOWN,turn);
        var sqChck:SeqCheck = new SeqCheck(CreateList.stepId);

    }

    private function mainProcess()
    {
        if (! rotateBool)
        {
            rotateBool = true;
            rotation_01.gotoAndPlay(rotation_01.totalFrames / 2 + rotation_01.currentFrame);
        }
    }


}

}

      

0


a source







All Articles