Actionscript 3 - Multiple variables for event listener.

Ok, I have a question (of course that is the reason why I am here).  I have been focusing on PHP a lot lately and just had a client that requires an MP3 player playing multiple songs so I had to whip out my rusty actionscript skills.  I have the player completed and it is working as desired.  The down side is it has multiple songs.  I am using separate functions for each song and separate event listeners.  My main question is there a way to combine these funtions into one and just use the event listener to pass another variable to the functions?  Below is a sample of one of the code for Song1.  I would like to make it so anywhere there is Song1 in the code, I can make it a variable so I can put in for example (Song2, Song3, Song4, etc.)  This way, I can have one or two functions handle all the songs instead of having to copy, paste and then find and replace.
Thanks for the help!
// Song 1
var Song1:Sound = new Sound();
pbSong1.source = Song1;
//pbSong1.visible = false;
var Song1Loaded:Boolean = false;
pbSong1.addEventListener(Event.COMPLETE, Song1LoadComplete);
btnSong1Play.addEventListener(MouseEvent.CLICK, Song1Play);
btnSong1Stop.addEventListener(MouseEvent.CLICK, Stop);
function Song1Play(event:MouseEvent) {
     if (Song1Loaded == true) {
          sndchnlMain.stop();
          sndchnlMain = Song1.play();
     } else {
          pbSong1.visible = true;
          Song1.load(new URLRequest("media/music/Song1.mp3"));
function Song1LoadComplete(event:Event) {
     trace("Size of file: " + Song1.bytesTotal);
     Song1.close();
     Song1Loaded = true;
     if(sndchnlMain) {
          sndchnlMain.stop();
     sndchnlMain = Song1.play();
     pbSong1.visible = false;

But if I reset the bolean to false, if the visitor goes to replay that song, it will try to load the song again.  I did find away around having to the use the boolean value though and accomplish the same thing (I am loving this).  I am using:
this["Song"+SongNum].bytesTotal
If there are bytes, then the song is loaded OR loading.  In order to check if the song is completely loaded before it plays, I am using this:
this["Song"+SongNum].bytesTotal == this["Song"+SongNum].bytesLoaded
This elimates the need for the Boolean I was using.  Also instead of for each song defining:
pbSong1.source = Song1;
I am using the main function to do it for me:
this["pbSong"+SongNum].source = this["Song"+SongNum];
The reason why I asked about the Sound variable, I was currious if I could do the same with it as I did with the Progress Bar Source as shown above?  Instead of defining this first:
var Song1:Sound = new Sound();
Can I do this in the function:
var this["Song"+SongNum]:Sound = new Sound();
I tried it once but I got an error.
Here is the new FULL updated code:
import fl.controls.ProgressBar;
import flash.events.ProgressEvent;
import flash.events.IOErrorEvent;
import flash.net.URLRequest;
import flash.media.SoundChannel;
import flash.media.Sound;
import flash.events.MouseEvent;
import flash.events.Event;
import flash.display.MovieClip;
var sndchnlMain:SoundChannel;
ClearNowPlaying();
  Song 1 Definitions
var Song1:Sound = new Sound();
pbSong1.addEventListener(Event.COMPLETE, LoadComplete);
btnSong1Play.addEventListener(MouseEvent.CLICK, PlaySong);
btnSong1Stop.addEventListener(MouseEvent.CLICK, Stop);
  Song 2 Definitions
var Song2:Sound = new Sound();
pbSong2.addEventListener(Event.COMPLETE, LoadComplete);
btnSong2Play.addEventListener(MouseEvent.CLICK, PlaySong);
btnSong2Stop.addEventListener(MouseEvent.CLICK, Stop);
  Song 3 Definitions
var Song3:Sound = new Sound();
pbSong3.addEventListener(Event.COMPLETE, LoadComplete);
btnSong3Play.addEventListener(MouseEvent.CLICK, PlaySong);
btnSong3Stop.addEventListener(MouseEvent.CLICK, Stop);
  Song 4 Definitions
var Song4:Sound = new Sound();
pbSong4.addEventListener(Event.COMPLETE, LoadComplete);
btnSong4Play.addEventListener(MouseEvent.CLICK, PlaySong);
btnSong4Stop.addEventListener(MouseEvent.CLICK, Stop);
  Song 5 Definitions
var Song5:Sound = new Sound();
pbSong5.addEventListener(Event.COMPLETE, LoadComplete);
btnSong5Play.addEventListener(MouseEvent.CLICK, PlaySong);
btnSong5Stop.addEventListener(MouseEvent.CLICK, Stop);
  Universal Functions
function Stop(event:MouseEvent) {
     sndchnlMain.stop();
     ClearNowPlaying();
function PlaySong(event:MouseEvent) {
     var SongNum:int = Number(event.currentTarget.name.split("btnSong").join("").split("Play").join(""));
     if (this["Song"+SongNum].bytesTotal) {
          if (this["Song"+SongNum].bytesTotal == this["Song"+SongNum].bytesLoaded) {
               sndchnlMain.stop();
               ClearNowPlaying();
               this["NowPlayingSong"+SongNum].visible = true;
               sndchnlMain = this["Song"+SongNum].play();
     } else {
          this["pbSong"+SongNum].source = this["Song"+SongNum];
          this["pbSong"+SongNum].visible = true;
          this["Song"+SongNum].load(new URLRequest("media/music/Song"+SongNum+".mp3"));
function LoadComplete(event:Event) {
     var SongNum:int = Number(event.currentTarget.name.split("pbSong").join(""));
     trace("Size of file: " + this["Song"+SongNum].bytesTotal);
     this["Song"+SongNum].close();
     this["Song"+SongNum+"Loaded"] = true;
     if(sndchnlMain) {
          sndchnlMain.stop();
     ClearNowPlaying();
     this["NowPlayingSong"+SongNum].visible = true;
     sndchnlMain = this["Song"+SongNum].play();
     this["pbSong"+SongNum].visible = false;
function ClearNowPlaying() {
     NowPlayingSong1.visible = false;
     NowPlayingSong2.visible = false;
     NowPlayingSong3.visible = false;
     NowPlayingSong4.visible = false;
     NowPlayingSong5.visible = false;

Similar Messages

  • CUOM 2.3 sends multiple notifications for Event StoppedGSUPerformancePolling with same time stamps

    Hi Alll,
    I have a CUOM Version 2.3 which shows mutiple notifications per Device for Event StoppedGSUPerformancePolling with same time stamps. The message below is generated from the default All_Events for all devices.
    Does anyone have a solution for that.
    Regards Michael
    This message is generated 8 times with the same time stamp in all messages.
    ** This message is generated from Cisco Unified Operations Manager **
    ALERT ID                = 00012OW
    CREATION TIME           = Sat 30-Oct-2010 16:31:57 CEST
    MODIFIED TIME           = Sat 30-Oct-2010 17:00:58 CEST
    STATUS                  = Active
    SEVERITY                = Critical
    MANAGED OBJECT          = 183.201.141.193
    MANAGED OBJECT TYPE     = VoiceGateway
    ASSOCIATED EVENTS       =
        Cleared:183.201.141.193:Unresponsive
        Active:183.201.141.193:StoppedGsuPerformancePolling
    CUSTOMER IDENTIFICATION = Voice Port
    CUSTOMER REVISION       = Voice Port

    if you get SNMP timeout on multiple devices then the fault usually lies in the path that the polling follows to get to these devices and back to the server.
    The problem obviously lies in the part path they have in common.
    It is not unusual to see the highest backbone loads during the night, due to backups being taken.
    Make sure the most important inter-switch links have no errors.
    I would rather fix this then turn off alerting.
    Cheers,
    Michel

  • Multiple seats for event booking

    Hi everyone,
    My event bookings form is currently set up to only take 1 booking at a time. I found the information at the following url to extend the form for multiple bookings:
    https://forums.adobe.com/docs/DOC-1774
    It said to add the following input field to the form:
    <input class="cat_textbox" id=BookingAllocation name=BookingAllocation>
    I just have two questions about this. Firstly, if I go into my form and add in a custom field, I get the following code:
                <tr>
                    <td><label for="CAT_Custom_330508">How many seats would you like to book? <span class="req">*</span></label><br />
                    <input type="text" maxlength="4000" name="CAT_Custom_330508" id="CAT_Custom_330508" class="cat_textbox" /></td>
                </tr>
    Each of the "name", "id" and "for" attributes in the above code, all have a custom field number, ie. Custom_330508. From what I have read, apparently I'm not supposed to change these as this is what BC uses to insert the data into the correct field within the CRM. The "id" and "name" values from the input field that I got from the abovementoned url are:
    id=BookingAllocation name=BookingAllocation
    So the problem is how can I get it to work if I'm not supposed to change the custom field number from my BC form. Also, once a person has entered a number into that field how can I get that field to update the amount field lower down on the form, ie. to multiply the number by the event cost?
    I'd really appreciate any help.

    Hi,
    In iChat 2 it was possible to have one name and Chat to it (Text only) in two locations (Chatting to your self as it were)
    In iChat from iChat 3 you can set each Mac at one location to allow Multiple Logins with the same Screen Name.
    This on the whole means that all computers will "Answer" an IM and show at least one side (incoming) of the Chat.
    Now in addition to this you can also set iChat to Not accept Off Line IMs (either by answering the questioning IM from AIM or on the AIM web site - you can login with your @mac.com name)
    as well as that iChat can be set in the General Preferences to "When iChat is Quit, Set My Status to Off Line"
    this effects not only Off Line IMS but also the fact iChat will start Up if the computer is On and someone IMs you.
    My experience is that it does not seem to be consistent and that the above settings seem to have something to do with it.
    There does not seem to be a limit to the number of Multiple Logins that you can have. (seats as you put it)
    Jabber accounts do not allow Multiple logins so the issue does not arise as you cannot essentially login on multiple computers.
    Summary.
    The best thing I can suggest is tweaking the General settings and see if things change
    9:36 PM Thursday; January 21, 2010
    Please, if posting Logs, do not post any Log info after the line "Binary Images for iChat"

  • Multiple recipients for event notifications/alarms

    Is it possible to send event notifications to mutiple email address.
    We use Convergence with latest patch level and Calendar Server 6.3
    Thanks for any hints or howtos
    Edited by: toni1988 on 30.04.2013 08:52

    I believe Calendar Server 6 supports only one notification address. CS7 supports multiple.

  • Multiple Places for Event Folder?

    I have a Christmas 2008 Event Folder - I went to 2 cities for this christmas - my family in Smithville, GA and my husbands family in Jonesville, GA... All the photos inside the folder are labeled according to each city, but...
    I would like to just have "one" event folder named: Christmas 2008. So when naming the Event Folder - do I have to choose which city I want to put as the place name, or is there a way to add both cities somehow?

    Yon can events and name them as you see fit
    If you adding a place to an event it is assigned to the event (everything in the event)
    YOu can select one or move photos and click on the "i" to turn them over and assign a place to them instead of assigning a lace to the entire event
    LN

  • Restriction with multiple variables for a characteristic present in Row

    Hi all,
    I am facing a problem when I am restricting a characteristic in the 'defaut value' section of the filter tab.
    Details of the problem is given below:
    Characteristic is restricted by 3 variables. When I execute the query for the first time there are no problems. I can enter value for all the three varaibles.
    But when I want to change the variable value, the variable screen does not list the variables and the system displays the following message.
    'variables could not be processed'.
    Diagnosis
    In the query definition, the default values of characteristic are stored as variables. The system tires to fill these variables again from the last restrictions so that it can use them as default values. In this case, however, the restriction is so complex, that the variable values cannot be reconstructed from it.
    System Response
    Procedure
    Change the restrictions in the query result if necessary.
    Kindly help to resolve this issue.
    Thanks in advance.
    Meera

    Hi All,
    Even I faced the same issue, and the issue is resolved with above solution.
    Now the second time I'm able to see the variable in Analyser, but now the output is not getting refreshed as per the variable entry for the second time.
    Thanks,
    Gaurav

  • Listening in main application for event coming from custom component

    I have a custom component that im using for a login.  i watch videos and tutorials on how to pass variables between custom components and application. the problem im having is that must tutorials or explanation have you put the event on the custom component and then it refers to some function within the main app.
    Is there a way to just listen on the main app when that event kicks off? ive been trying for hours and i know there has to be something im missing it cant be that hard. any help i would really appreciate.
    Thanks
    Miguel

    Sounds like you're asking about addEventListener():
         <fx:Script>
              <![CDATA[
                   import mx.events.FlexEvent;
                   protected function windowedapplication1_creationCompleteHandler(event:FlexEvent):void
                        comp.addEventListener("test", testHandler);
                   private function testHandler(e:Event):void {
                        trace(e);
              ]]>
         </fx:Script>
         <local:TestComponent id="comp"/>
    Add an event listener on your custom component (first string is the 'type' of the event).

  • Multiple lines of event title and location failed to show for All Day event in SharePoint 2010 Calendar

    I have a calendar with SPD workflow to display multiple lines for Title, Attendees, Location.
    1. Created a custom columne "Breaklines" and set to "Multiple lines of text"
    2. Set Monthly View to display the "Breaklines"
    3. in SPD I created a workflow like this:
    4. On the Calendar page, I used a javascript to remove the <br/>
    <script src="http://code.jquery.com/jquery-1.10.2.min.js"
    type="text/javascript"></script><script
    type="text/javascript">
    function updateCalendarWeekday()
       $('.ms-acal-title').each(function(){
        var str = $(this).html();
        str = str.replace(/&lt;/g,
    "<");
        str = str.replace(/&gt;/g,
    ">");
        $(this).html(str);
    _spBodyOnLoadFunctionNames.push('calendarEventLinkIntercept');
    // hook into the existing SharePoint calendar load function
    function calendarEventLinkIntercept()
       var OldCalendarNotify4a
    = SP.UI.ApplicationPages.CalendarNotify.$4a;
       SP.UI.ApplicationPages.CalendarNotify.$4a
    = function ()
          OldCalendarNotify4a();
          updateCalendarWeekday();
    }</script><style>
    .ms-acal-item
                    HEIGHT:
    60px !important
    .ms-acal-summary-itemrow
                    HEIGHT:
    85px !important
    }</style>
    Everything works fine, except that when the All Day event is checked, the display screwed like this:
    I guess that when the event is All Day Event, the Start Time and End Time is not filled by the user (although they show in the form as 12:00 am -11:59PM), so the top line space is now used to display Title and Location. Since the Top Space for
    Start and End Time is a single line, it displays everything on one line. Plus the script does not act on this space.
    Does anyone know a fix for this problem?
    Thanks for any tips!

    Is there a way to modify the javescript so that it also works in the "start-end time" space?

  • What is the best way to create shared variable for multiple PXI(Real-Time) to GUI PC?

    What is the best way to create shared variable for multiple Real time (PXI) to GUI PC? I have 16 Nos of PXI system in network and 1 nos of GUI PC. I want to send command to all the PXI system with using single variable from GUI PC(Like Start Data acquisition, Stop data Acquisition) and I also want data from each PXI system to GUI PC display purpose. Can anybody suggest me best performance system configuration. Where to create variable?(Host PC or at  individual PXI system).

    Dear Ravens,
    I want to control real-time application from host(Command from GUI PC to PXI).Host PC should have access to all 16 sets PXI's variable. During communication failure with PXI, Host will stop data display for particular station.
    Ravens Fan wrote:
    Either.  For the best performance, you need to determine what that means.  Is it more important for each PXI machine to have access to the shared variable, or for the host PC to have access to all 16 sets of variables?  If you have slowdown or issue with the network communication, what kinds of problems would it cause for each machine?
    You want to located the shared variable library on whatever machine is more critical.  That is probably each PXI machine, but only you know your application.
    Ravens Fan wrote:
    Either.  For the best performance, you need to determine what that means.  Is it more important for each PXI machine to have access to the shared variable, or for the host PC to have access to all 16 sets of variables?  If you have slowdown or issue with the network communication, what kinds of problems would it cause for each machine?
    You want to located the shared variable library on whatever machine is more critical.  That is probably each PXI machine, but only you know your application.

  • Is there any event listener for changing the selection of layer?

    Hi all,
    I am looking into an event listener which fires on changing the selection of layer. I found 'Select' event listener which fires on selecting the different object.
    Actually the problem with Select event listener is that when we select an object and move it and deselect it by clicking on the document, event fires on the selection of that object. But if we again select the same object and move it, no event is fired at that time.
    Is there any workaround of this? So that the event is fired every time when we select the same object.
    Please help me on this..
    Regards,
    VG.

    Thanks for the reply..
    Actually I want the same behaviour as in illustrator i.e
    - Select a layer. (Notifier calls the listener)
    - Move it.
    - Click on the document.
    - Again select the same layer. (Notifier calls the listener again)
    - Move it.
    But in photoshop,
    - Select a layer. (Notifier calls the listener)
    - Move it.
    - Click on the document.
    - Again select the same layer. (Notifier doesnot calls the listener again as the layer is already selected in panel as you explained.)
    - Move it.
    Is there any way to get the same behaviour of illustrator in photoshop?

  • Listen for Events from anywhere

    Hello!
    I have an application with a rather complicated component hierarchy.
    How can I have it so that I can listen for events from any component in any component, regardless of who is who's child?
    Thank you!

    You need a broadcasting mechanism.
    Many architecture framework offers this facility, but as a quick hack you can try something like
    public class Broadcaster extends EventDispatcher  ( singleton anti pattern   )
    instance
    then just do Broadcaster.instance.addEventListener or removeEventListener. it's a crappy singleton, but at least it does not hold any global state.
    I've also seen people use Application.application to dispatch/listen globally but really don't like it.
    Note : Use weak references or your views will never be eligible for garbage collections.

  • Events cannot have multiple exceptions for the same date

    I just starting getting this message and could not sync to one of my Google calendars. I'm posting this for others who might get the same problem.
    I didn't find the answer on these forums but did find it on this thread on Google:
    http://www.google.com/support/forum/p/Calendar/thread?tid=241155f758d9e2a4&hl=en
    Here's the important excerpt:
    "I had a client, who just had this same issue, nothing to do with Google cals.
    It was apparently, in my best guess, a corruption of the subscribed cal.
    *I did a get info on the cal, copied the URL, deleted the cal, then re-subscribed to it by pasting in the URL, and now it's working fine*."

    I've been having the same problem with my iCal calendars and the "Events cannot have multiple exceptions for the same date" error. Once it gets going, it uses up a lot of the CPU and resources. After reinstalling iCal, all my calendars were missing and I could not even resubscribe to them.
    I took my MacBook Pro to the Apple Store, and they were able to solve the problem by moving some of the iCal files from their existing folders out to the desktop, and reopening the program. That got it working, however, now I'm having the same problem again. So back to square one. Anyone else having this issue and know the cause?
    My setup is my MacBook Pro uses Entourage, use that calendar in my iCal. And I subscribe to two calendars my wife publishes on her Macbook. We're both using Snow Leopard.

  • Reg: Multiple Ranges for Variables

    Hello Gurus,
    We have a requirement to have Multiple Ranges for Variables and I have gone through the document below which is applicable to 2004s SP 07.
    We are on CE 7.1 SP 3 I was looking for a similar document which can guide me to create Multiple Value ranges in CE.
    http://www.sdn.sap.com/irj/scn/go/portal/prtroot/docs/library/uuid/07134c67-0b01-0010-0493-b89287cf330f?quicklink=index&overridelayout=true
    If this is not available in SP 3 is there a Workaround to have the same kind of functionality.
    Thanks & Regards,
    Pramod

    Hi Pramod,
    If I understand correctly, u want to send a range of values to the variable of a query.
    This can be done using " ; ". syntax is [value 1];[value 2];[value 3]
    If you want to send two dates to a query date variable... take two date fields then pass to the variable date1;date2 (while creating query you took variable of type range)
    Thanks,
    Pradeep

  • Sevice Contract - Listener for Events Queue Issue

    Hi,
    The Listener for Events Queue in our Production environment ran very long, It took about 3+ hrs to complete the program. Is there any thing specific that we can check as part of RCA.
    Further there were 'library cache lock' found ... how this can impact the performance and how library cache lock works.
    Regards
    Tauseef E Ahmad

    Hi Team,
    i used the following code for recognizing the key events.
    String javaScriptKeyListener =
    " function keyListener() "
    +" { "
    +" alert(window.event.keyCode) ; } ";
    OAWebBean body = pageContext.getRootWebBean();
    if (body instanceof OABodyBean)
    ((OABodyBean)body).setOnLoad("onKeyPress = javascript:keyListener()");
    but it is not working as expected..
    Any suggestions ??
    Regards
    Sridhar

  • Error ocurring when Event Listener methode in "for statement" is called

    Hy guys,
    I would be gratefull if somebody could answer me how can I
    call a method from flex in "for statement", that is actually in my
    remote service implemented. I call the method loadAssetsResult()
    (event listener method in my action script) and get a collection of
    objects back. In the same method I want to iterate throught this
    collection and call another method from remote service, that is
    specified for this object. Problem is when I call this remote
    method inside of this loop statement. I get the error when I write
    my code like following one:
    public function loadAssetsResult(event:ResultEvent):void {
    for (i=0; i<event.result.length; i++) {
    a = new Asset();
    a.longName = event.result
    .longName;
    a.shortName = event.result.shortName;
    a.isin = event.result
    .isin;
    a.nsin = event.result.nsin;
    a.currentDayClose = event.result[0].currentQuote.dayClose;
    //Schluskurs
    assets.addItemAt(a, i);
    RO.getIndicatorCollection(i);
    DataBinding();
    When I comment the row: RO.getIndicatorCollection() it works,
    of course without these additional data that I get from that
    method. I need to call this method inside loop statement (for each
    object), but I don't know how, without getting this error?
    please somebody help me with some ideas
    br
    Sheila

    Kris,
    First of all you should increase the value of logging-config/character-limit element in tangosol-coherence.xml to see the message entirely. The default setting is 4096 which is not enough to see your exception text.
    When you do that I believe you will see that the actual exception is java.lang.ClassNotFoundException indicating that the node that has the listener installed doesn't know about the class that is being put into the cache and could be easily fixed as shown here: http://www.tangosol.com/faq-coherence.jsp#classnotfound
    Please let me know if that doesn't help.
    Gene

Maybe you are looking for