1 btn 2 events in AS3

I'm trying to create a conditional statement where when I
click a button it will go to one frame, play and then once the clip
is triggered to stop it will go to another frame and play. I can
figure out how to make a button go to one frame and play but I
can't figure out how to actionscript 3 it to then go the next frame
one this is completed. I basically want to create a site that will
operate like this:
http://www.deutschinc.com/
I think I can handle the if construction to make the right
clip leave the scene.
Please help!
Thanks

Thanks for the response but I'm still a bit confused because
I'm pretty new to this. The code I have in my experimental file
creates the first action like this:
yellow_btn.addEventListener(MouseEvent.CLICK, yClick);
function yClick(event:MouseEvent):void{
gotoAndPlay(2)
At this point I would like it to jump to frame 31 once it has
finished nine frames starting with frame 2 (frame 10 has a stop();
on it). What do I need to cade now? Does it start w/an event
listener?
Thanks,
K-

Similar Messages

  • How to Access Custom Event using AS3?

    Hi All,
    Maybe it's that its Monday morning and my brain is still foggy, but I can't seem to figure out how to set custom events using AS3.
    I have a custom GridRow itemRenderer, and have declared the event using the appropriate metatags.
    Then I create the GR item dynamically using AS3 instantiation, but the event is not available for selection in the intellisense drop-down.
    Let's take the following as an example:
    <?xml version="1.0" encoding="utf-8"?>
    <mx:Grid
         xmlns:mx="http://www.adobe.com/2006/mxml"
         xmlns:renderers="com.brassworks.renderers.*"
         creationComplete="componentInit();"
    >
         <mx:Script>
              <![CDATA[
                   private function componentInit():void
                        newRow     :MyRow     = new MyRow();
                        //newRow.myEvent is not an available option to set
              ]]>
         </mx:Script>
    </mx:Grid>
    Then the itemRenderer:
    <?xml version="1.0" encoding="utf-8"?>
    <GridRow
         xmlns:mx="http://www.adobe.com/2006/mxml"
         xmlns:classes="com.brassworks.components.classes.*"
         creationComplete="componentInit();"
    >
         <mx:Metadata>
              [Event(name="myEvent", type="flash.events.Event")]
         </mx:Metadata>
         <mx:Script>
              <![CDATA[
                   private function itemChanged(event:Event):void
                   Alert.show("test");
                   this.dispatchEvent(new Event("myEvent"));
              ]]>
         </mx:Script>
         <mx:GridItem>
              <mx:TextInput
                   change="itemChanged"
              />
         </mx:GridItem>
    </GridRow>
    How do I go about setting the handler method for custom events on instantiated items? Do I need to do this via the AddEventListener() method? Does this mean that events aren't exposed in ActionScript like they are in MXML? (In MXML all I have to do is <MyRow myEvent="handler(event)" />.)
    Thanks!
    -Mike

    Yes, I you need to do this via the addEventListener() method.
    myRow.addEventListener( "myEvent", myHandler );
    I hope that helps.
    Ben Edwards

  • Custom event in as3

    Custom event example in as3
    Hi,
    Event listener model in cs3 looks nice it is not same as we
    were heaving earlier in as2 or till flash 8.
    Here is an example of using and making your own custom event
    in as3.
    This example allow user to load n number of XML file when XML
    file is loaded then dispatch an event "XMLLoaded" which can be
    listen by any other class any where.
    There are two class
    1. CustEvent
    2. DEvt
    Here are the definition of both class
    CustEvent.as
    * Author - Sanjeev Rajput
    * Date - 16-July-07
    * class is used to load any XML file and dispatch an event
    when XML is loaded
    package eventDispatch{
    import flash.events.Event;
    public class CustEvent extends Event {
    public static const XMLLoaded:String = "XMLLoaded";// Event
    Name
    public var XMLData:XML // loaded XML data
    public var XMLRef:String // XML file name
    public function CustEvent(type:String,
    param:String,param1:XML) {
    this.XMLData= param1;
    this.XMLRef=param;
    super(type);
    DEvt.as
    * Author - Sanjeev Rajput
    * Date - 16-July-07
    * class is used to load any XML file and dispatch an event
    when XML is loaded
    package eventDispatch{
    import flash.events.EventDispatcher;
    import flash.net.URLLoader;
    import flash.events.Event;
    import flash.net.URLRequest;
    public class DEvt extends EventDispatcher {
    private var xmlLdr:URLLoader;
    private var urlr:URLRequest;
    private var xmlpath_str:String;
    public var XMLData:XML;
    private var counter:int=0;
    private var xmlRequestArr:Array
    public function DEvt():void {
    this.xmlRequestArr=new Array()
    public function loadXML(fileRef:String,xmlRef:String):void {
    this.xmlpath_str=fileRef;
    this.xmlRequestArr.push(xmlRef)
    this.xmlLdr = new URLLoader();
    this.urlr=new URLRequest(this.xmlpath_str);
    this.xmlLdr.addEventListener(Event.COMPLETE,
    completeHandler);
    this.xmlLdr.load(this.urlr);
    private function completeHandler(evt:Event) {
    this.XMLData=new XML(evt.target.data);
    this.dispatchEvent(new
    CustEvent(CustEvent.XMLLoaded,this.xmlRequestArr[this.counter],this.XMLData));
    this.counter++
    evtDispatchExample.fla
    Inside this fla on very first frame I have following code
    import eventDispatch.*;
    var DEvt_obj:Evt=new DEvt();
    DEvt_obj.loadXML("xml.xml",'xml0 File');
    DEvt_obj.loadXML("xml1.xml",'xml1 File');
    DEvt_obj.loadXML("xml2.xml",'xml2 File');//----and so on---
    DEvt_obj.addEventListener(CustEvent.XMLLoaded,XMLL oaded);
    function XMLLoaded(evt:CustEvent) {
    //--- here we can check which XML file is loaded----
    if(evt.XMLRef=='xml0'){
    //--- do necessary task when this file loaded
    //---XML data can be found in evt.XMLData
    trace(evt.XMLData) //-- property of CustEvent class
    if(evt.XMLRef=='xml1'){
    //--- do necessary task when this file loaded
    //---XML data can be found in evt.XMLData
    trace(evt.XMLData) //-- property of CustEvent class
    //---- and so on for n number of XML file----
    }

    Have you tested this online with varyious file sizes? Seems
    to me there that
    there is no guarantee as to when a loader will complete its
    task. If the
    second request completed before the first, how would you
    dispatch the
    correct information?

  • What is the conversion of onload event to AS3 ?

    I have following code on AS2 . Now I need to convert into AS3. Please give your idea to change into AS3
    myxml2.onLoad = function() {
         // functionality goes here
    myxml.load(my.xml);

    var xml:XML;
    var url:String = "sample.xml";
    var req:URLRequest = new URLRequest(url);
    var loader:URLLoader = new URLLoader(req);
    loader.addEventListener(Event.COMPLETE, loaderCompleteHandler);
    function loaderCompleteHandler(event:Event):void {
        xml = new XML(event.currentTarget.data);
        trace(xml.toXMLString());
    Or one could always RTFM: Reading external XML documents
    http://livedocs.adobe.com/flash/9.0/main/00000132.html

  • Fire Custom Event in as3

    Hello All,
    I have an variable of type boolean , and I want to fire event when I change the value of this variable , how can I do that in AS3
    Thanks in Advance

    Thank you for your help
    I have tried this solution but it doesn't work with me
    may be I have so explain my proplem in more details
    I have two XML files , the first file has some configration options I want to load for my Project , and I want to make sure that I have load them before loading the second file that will have the data
    I have define the loader and handle the onComplete event and parse the first file and make some operations and when I call the function that will load the second file after the last operation of the handler of the first file it load it more than once
    and If I call it after the calleng of the first file haldler it call it once but it doesn't execute the operations
    Thanks in Advance

  • What is AS2 for Event.REMOVED_FROM_STAGE (AS3)?

    Hi,
    I am used to AS3 and am translating back to AS2.  I want to check if something has been removed from the stage.  In AS3, I used this:
    obj.addEventListener(Event.REMOVED_FROM_STAGE, objRemovedFromStageHandler);
    How can I do this in AS2?
    I have been trying to use the delegate class to set up an onEnterFrame event that I can then remove.  I have this working with events for button clicks etc but not onEnterFrame.  Well, i can get it working, but how do I set it up so I can remove a specific onEnterFrame, as I need to use multiple onEnterFrame throughout the script?
    Any suggestions very welcome.
    Many thanks,
    Mike

    in as2 you can just check if the object exists:
    if(obj)
    but no event is dispatched.
    if it does it's either on-stage or on the back-stage which you can check if needed.

  • JAVA Events like AS3 dispatchEvent and addEventListener

    I've developed flash based content for years and have got into JAVA now. I've written a few programs now, but there is a feature of as3 I'd like to be able to use in JAVA. That feature is adding, removing, and dispatching Events.
    For example, in flash I could do this:
    public class example1 extends MovieClip {
    public example1() {
    public fireEvent() {
    this.dispatchEvent(new Event("somethingSpecialGoesHere"));
    Then I could call the class and listen for an event from a parent class like this:
    public class parentClass extends MovieClip {
    public parentClass():void {
    var tester:example1 = new example1();
    tester.addEventListener("somethingSpecialGoesHere", eventFunctionToFire);
    private eventFunctionToFire(evt:Event):void {
    trace("Event Fired");
    How can I apply this into java programs? Where say I have a parent class - Launcher, which instanciates the child class xmlRead. I want to add an event listener to the instanciated child in Launcher, and then dispatch the event from within the child xmlRead.
    How can I go about this? Any ideas? Thanks.

    I don't know Flash nor AS3, but an epdermic reaction is that you should study a technology, especially an established one, for what it's worth, and how it's generally used, and not necessarily try to force one language's idiom into another language.
    That being said I understand that it's easier t learn from something you're already familiar with. The closest to what you describe in terms of event listening, is described here. Such a event-generator idiom is explicitly supported only by a small number of built-in classes (especially, GUI classes), but can be implemented [fairly easily|http://www.artima.com/designtechniques/eventgen.html] in custom classes as well.

  • Passing Param to Mouse Event in AS3

    Hello All,
    I want to make a tooltip box , when I mouse over an object it will appear with the object color and some other data
    how can I send the color param and other param to mouse event?
    Thanks in Advance

    Hi,
    Maybe this will help you :-
    http://www.ultrashock.com/forums/actionscript/as3-adding-parameter-to-eventlistener-104729 .html
    http://www.orlandmedia.com/blog/actionscript-3/passing-parameters-to-a-mouseevent-listener /

  • OnLoad Event in as3????

    please change this code to as3 code.....
    mymc.onLoad=function()
       trace("onLoad is working!")

    please change it yourself
    http://www.adobe.com/devnet/actionscript/as3_migration_table.html

  • Manually dispatching event in as3

    hi:
    how can I simulate events for a demo like in this example:
    import flash.events.*;
    function traceTxT(e:MouseEvent):void {
      trace("button clicked");
    blueBtn.addEventListener(MouseEvent.CLICK, traceTxT);
    if I add:
    blueBtn.dispatchEvent(new Event(MouseEvent.CLICK));
    I receive this error:
    TypeError: Error #1034: Type Coercion failed: cannot convert flash.events::Event@1d7eed81 to flash.events.MouseEvent.
    at flash.events::EventDispatcher/flash.events:EventDispatcher::dispatchEventFunction()
    at flash.events::EventDispatcher/dispatchEvent()
    at dispatcher_fla::MainTimeline/dispatcher_fla::frame1()
    thanks in advance

    use:
    blueBtn.dispatchEvent(new MouseEvent(MouseEvent.CLICK));

  • AS3 code for Mouse Event

    Hi,
    I had uploaded jpeg file onto the stage using
    File->Import.
    Now, how to access the mouse-events using AS3.0?
    i.e., when we click with mouse on the stage
    it should display the x and y co-ordinates of the point
    being clicked.
    These x and y coordinates must be displayed in text-boxes
    provided down on the same stage.
    Please reply me

    You can do show/hide movieclip on mouseover. get your box
    position and assign to the popup (tooltip movieclip).
    see this...
    not tested. but it should work.
    import flash.events.MouseEvent;
    function showClip(evt:MouseEvent) {
    tooltips.x = evt.target.x + evt.target.width;;
    tooltips.y = evt.target.y - evt.target.height;
    tooltips.visible = true
    function hideClip(evt:MouseEvent) {
    tooltips.visible = false;
    box.addEventListener(MouseEvent.MOUSE_OVER, showClip);
    box.addEventListener(MouseEvent.MOUSE_OUT, hideClip);
    I assume you'll create two movieclips named: box and tooltips

  • FLVPlayback false event complete triggered

    I am facing a problem with FLVPlayback complete event with AS3 publishing for FlashPlayer 11.1
    The trouble is that after a few seconds of the video starts the complete event is triggered and the problem always occurs only after a few hours of playing a playlist of videos.
    Some code here:
    var my_player:FLVPlayback = new FLVPlayback();
    function makePlayer():void{
      my_player.scaleMode = "exactFit";
      my_player.x = video_x;
      my_player.y = video_y;
      my_player.width = video_width;
      my_player.height = video_height;
    if(bBordi)
      my_player.mask = mask_mc;
      video.addChild(my_player);
      my_player.source = my_path + my_videos[nVideo].@URL;
      my_player.addEventListener(fl.video.VideoEvent.COMPLETE, completePlay);
      my_player.volume=video_volume;
    function completePlay(e:fl.video.VideoEvent):void
       if(!my_player.stopped)
       return;
      trace("VIDEO ENDED: " + my_path + my_videos[nVideo].@URL)
      nVideo++;
       if(nVideo >= my_total)
      nVideo = 0;
      playPlayer();
    function playPlayer():void{
      my_player.source=(my_path + my_videos[nVideo].@URL);
      my_player.play();

    there may be some problem when retrieving the flv from the browser's cache, then.  you could prevent caching by using something like:
    my_player.source = my_path + my_videos[nVideo].@URL+"?"+getTimer();

  • How to call a function/event after a Remote Object's data is loaded?

    I'm making a call to a remote object that is loading a good
    amount of data. I've set up a "please wait" label that is supposed
    to display while the data is being loaded and then clear the label
    when the data finishes loading.
    At the moment I've got it set up like so...
    label = 'Loading data, please wait..."
    remoteObj.read.send();
    label = ''
    The problem with this is that the 'please wait' label doesn't
    even display because the actual call to the remote object I'm
    making finishes so quickly even though the data load does not. So
    what I need is possibly an IF statement to check if the data has
    finished loading. If it hasn't finished loading, the label stays in
    the "please wait" status, or if the data does finish loading, then
    the label clears out.
    What would be ideal is...
    remoteObj.read.send(); // gets the data
    if(data is loaded){
    label = '';
    }else{
    label = 'Please wait'
    I just don't know how to form the statement for the data
    loading in the IF statement.

    You are seeing the difference between data loading and UI
    rendereing.
    Reasonable amounts of data load very fast, expecially with
    RemoteObject. Bur rendering the UI is almost always the bottleneck,
    event with AS3 FP8+, which is about 30 percent faster than AS2!
    I have not found a perfect solution for this myself, but i
    think you will want to look into the component data events, to find
    one that fires after the component is actually rendered.
    Tracy

  • Problems with events in flex

    Hi there. I'm a AS2 and Flash CS3 guy. I started to learn AS3 and transfer to Flex 3. But I got a problem w/ Events in AS3. I'm adding a canvas component to the stage. On that canvas, I added 3 different events: mouse down, mouse move, and mouse up. When mouse move is fired, there is no way for me to get mouse up event fired, and viceversa, when mouse up is fired, there is no way to get the mouse move event fired. Is there any one to help this newbie with this particular problem? Any help will be very appreciated.
    Code:
    <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute">
    <mx:canvas id="myCanvas" x="50" y="50" width="500" height="500" click="event_1();" mouseMove="event_2();" mouseUp="event_3();">
    </mx:Canvas>
    <mx:Script>
    <![CDATA[
    import mx.controls.Alert;
    import flash.events.*;
    public function event_1():void
    { Alert.show("First event fired"); }
    public function event_2():void
    { Alert.show("Second event fired"); }
    public function event_3():void
    { Alert.show("third event fired); }
    </mx:Script>
    </mx:Application>

    Hi Greg. Thank you for your replay. The question is I didnt want to bother you with the complete code and post it with the minimal expression. But here I give you the full code w/corresponding package. What I'm trying to do is drawing a line over an empty canvas (I got it very easily in Flash AS2)
    Code:
    <?xml version="1.0" encoding="utf-8"?>
    <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" initialize="addChild(p1)">
    <mx:Canvas id="wrapper" x="10" y="10" width="600" height="600">
      <mx:Canvas x="50" y="50" width="500" height="500" id="imageView" backgroundColor="#F8F3F3" click="startDraw();" mouseMove="drawLine();" mouseUp="noDrawLine();" >
      </mx:Canvas>
    </mx:Canvas>
    <mx:Button x="263" y="618" label="Draw Line" click="prepToDraw();"/>
    <mx:Script>
    <![CDATA[
      import com.myDomain.Lines.Main;
       import mx.graphics.*;
       import mx.binding.utils.BindingUtils;
       import flash.events.IOErrorEvent;
       import flash.events.Event;
       import flash.display.*;
       import mx.controls.Alert;
       import com.myDomain.Lines.Main;
       public var p1:Main = new Main();
       public var pre:Number = 0;
       public function prepToDraw():void
        pre = 1;
       public function startDraw():void
        if(pre == 1)
        p1.graphics.clear();
        var newColor:int = 0xFF00FF;
        var iniX:Number = mouseX;
        var iniY:Number = mouseY;
        var lineWidth:Number = 10;
        p1.graphics.lineStyle(lineWidth, newColor);
        p1.graphics.moveTo(iniX, iniY);
       public function drawLine():void
        if(pre == 1)
         p1.graphics.lineTo(mouseX, mouseY);
       public function noDrawLine():void
        if(pre == 1)
         Alert.show("noLine");
    ]]>
    </mx:Script>
    </mx:Application>
    The package:
    package com.myDomain.Lines
    import flash.display.Shape;
    import flash.display.Stage;
    import flash.events.MouseEvent;
    import mx.core.UIComponent;
    public class Main extends UIComponent
      public function Main()
       super();
      public var p1:Shape = new Shape();
    If you go apply the code, you will see: 1) The first event to fire is mouseUp, then you eill start drawing the line, but again, you will not be able to stop this event with mouseUp. If you can help me, I will be very appreciated. Thanks. 

  • Warning 1090 in AS3...?

    I need help with this AS3 code...
    shinyButton.onRollOver = function() {
              this.glitter.play();
    I keep getting this error-
    Warning: 1090: Migration issue: The onRollOver event handler is not triggered automatically by Flash Player at run time in ActionScript 3.0.  You must first register this handler for the event using addEventListener ( 'mouseOver', callback_handler).
    Please help ASAP.
    Thanks.

    where is glitter in relationship to shinyButton? inside of it? or outside of it? if it is inside, change your scoping:
    shinyButton.addEventListener(MouseEvent.MOUSE_OVER,overMouse);
    function overMouse(e:MouseEvent):void{
           e.target.glitter.play();
    and then brush up on your mouse events in as3 here:
    http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/events/MouseEvent .html

Maybe you are looking for