Add event listeners to dynamically loaded symbols?

Hi,
I'm trying to dynamically load different MovieClips based on user input. Several of those clips have embedded url link symbols. How can I add event listeners to the url links if the dynamically loaded MovieClip does not have an instance name? Seems like I can (right?) apply an instance name when the clip is loading, but the event listener doesn't compile because the name is not there yet, so that seems out.
Am I on right track?

Are you saying that you will instnatiate this symbol several times and each time url for this link is going to be different?
There are at list two ways to deal with it.
1. Inside symbol you can dispatch a custom event once it is clicked:
myLink.addeventListener(MouseEvent.CLICK, onClick);
function onClick(e:MouseEvent):void {
     dispatchEvent(new Event("linkClick"));
Wherever you instantiate the symbol (perhaps on timeline):
var symbolInstance:MySymbol = new MySymbol();
symbolInstance.addEventListener("linkClick", onLinkClick);
function onLinkClick(e:Event):void {
     // do whatever
Second way would be to pass url value into symbol instance itself and deal with with it on a symbol level. I personally prefere way 1.

Similar Messages

  • Loading/Unloading a .swf that adds event listeners to the Stage

    Hi all,
    Disclaimer
    Apologies if I suck so bad at using forum search that the answer to this is on page 1 somewhere; I tried...
    Question
    I am loading and unloading a .swf to which I do not have source code access. This .swf places several event listeners on the stage, as far as I can tell. When the .swf is unloaded, the event listeners placed upon the stage still seem to be in effect. Using unloadAndStop doesn't seem to do it, and I have to target Flash Player 9, anyway, so can't really use it. Is there any other way I can keep this external .swf from holding onto my main movie's stage?
    Additional info
    All eventListeners and references being set by my code are removed.
    I've managed a little contact with the author of the .swf:
    I've requested he provide a dispose() method I can call to get all the listeners removed, and send an updated .swf.
    He's suggested that I should be able to avoid the problem by loading into a unique ApplicationDomain. I'm not terribly familiar with this, but have given it a try without much success. Is this a valid solution - can I really protect my 'stage' by properly using ApplicationDomains - or do I need to persist in trying to get a public dispose() method built in?
    Thanks in advance!
    Cheers, John

    thanks for reply sir
    sir actually, i have not any problem with loading any file but i need to go back to intro.swf file when i click on clsbtn of main.swf, i want unload the main.swf file and panel.swf file
    actually i did was, i have intro.swf file and there is button by clicking load main.swf file (where is timeline controling butons) and in the main file automatically load panel.swf file ( where is all animation)
    its all play gud , no problem
    but my problem is there is a clsbtn in main.swf file and when i click on that button everything should be unload and it should return on the previous position in intro.swf
    i hope u understand what i am trying to say

  • Spry event listeners with dynamic form elements

    Hi ,
    I am trying to implement spry event listeners with a form that has dynamic check boxes and text field name. I now i can get the elements in a var and loop through with a normal function but can this work for spry events listeners

    Short answer is yes. But I have a feeling that you need further assistance, in which case give us a URL to a page that you want to apply the event listener to.

  • Urgent: How to add event listeners to a null object?

    I have an object that is lazy loaded, and therefore starts out null.
    How can I add an event listener onto this null object, so that it fires whenever the object is instantiated?
    WHY does arrayCollection.addEventListener(CollectionEvent.COLLECTION_CHANGED, function) not work??
    Thanks!
    C

    C,
    the answer to your question "WHY does arrayCollection.addEventListener(CollectionEvent.COLLECTION_CHANGED, function) not work??" is that addEventListener is not a static method, ie it has to be attached to an actual instance. I agree that in your situation it would be handy to have it as static, something like ArrayCollection.addEventListener(etc) but I'm not at all sure that is a good plan in general, as usually we want events to fire from an actual instance of the class, not generically. A quick look through the adobe docs has convinced me there are not many static methods at all, and none that appear to help you.
    I take it from your description that you don't know exactly when the collection is instantiated? But presumably though you do have a point where new is called? Or something equivalent like populating it from something else?
    Richard

  • Adding a javascript event to a dynamically loaded content

    Hello,
    I am new to adobe air. I am trying to create a desktop application with html and javascript. I have a page that reads data from db and lists each  records as links (a href). I need to assign an onclick event for each link.
    both
    foreach result {
         <a href="#" onclick="foo()">bla bla</a>
    and
    foreach result {
         document.getElementById('container').innerHTML = '<a href="#" id="link_id">bla bloa</a>';
         document.getElementById('link_id').addEventListener("click", function() { foo(); });
    With the second  solution it  only workd  for the last record
    What am I missing ?
    I appreciate any help.
    Thanks.

    I always recommend using a javascript framework such as jQuery for building JS AIR applications. If you're already using jQuery, or plan on it then look into jQuery's live binding:
    http://api.jquery.com/live/
    Essentially what it does is "listen" for new DOM elements that match events you're watching for and add them to your existing bindings. It's very simple. Your example below becomes:
    $('a').live('click', function(){
         // do something

  • My ipad2 cannot add events to calendars? There isn't a symbol "plus", and it doesn't response no matter how to tip it.

    My ipad2 cannot add events to calendars? There isn't a symbol "plus", and it doesn't response no matter how to tip it.

    This may sound a little stupid, have you tried turning on iCloud and test your calendar again.

  • After loading os7 on my i phone4 i cant add events?

    after loading os7 on my i phone4 i cant add events?

    settings - icloud - calendar - on
    ical  http://www.apple.com/support/ical/

  • Suddenly I can no longer add events to my calendar osuddr add reminders. The   symbol is brayed out and won't allow me to add anything???

    Suddenly I can no longer add events to my calendar or new reminders. The + is grayed out and won't allow any new additions???

    I had the the same problem albeit with an m4v (same hardware and OS rev too!, iTunes 10.6.3). I was able to add the movie to a new library per Limnos' suggestion here, indicating that iTunes wasn't totally busted. However, I was also able to see the movie in the Recently Added smart playlist (another hat tip to Limnos), although it still did not appear in the Movies section of my iTunes library. (It was also in the iTunes Library.xml file.)
    So I called AppleCare, and they directed me to move the file from the external drive where it was living, into the /Users/<Your Name Here>/Movies directory, and to "Add to Library" (Command-O) from that location. Sure enough (and much to my surprise), it showed up immediately (duplicated, actually) in the Movies section of my iTunes library. Subsequent additions to my Library have not misbehaved similiarly.

  • How to get a dynamically created symbol to delete itself on click?

    Here's the setup...
    I want to have a dynamically created symbol appear upon click of a hotspot. In this case, you click on a pulsating hotspot and a popup box appears.
    Here's the code I'm using for that.
    //Create an instance element of a symbol as a child of the given parent element
    var mySymbolObject = sym.createChildSymbol("gardern_toxins_popup","stage");
    So we have the symbol "garden_toxins_popup" from my library placed dynamically on the page. I would like to assign an action to the pop-up itself that allows you to remove the symbol from the stage upon click.
    I feel silly for not being able to figure this out. I tried iterations of this bit of code...
    //Get the stage from the composition level, get the symbol
    sym.getComposition().getStage().getSymbol("garden_toxins_popup").delete();
    ...but it doesn't work.
    So I tried thinking like I was back in Flash and tried the following...
    this.parent.removeChild(this);
    But no joy on that as well. Is there something I haven't addressed in this logic or am I going about it in the wrong way? Thanks!

    Hi, chirpieguy-
    You'll want to use the deleteSymbol() API.
    http://www.adobe.com/devnet-docs/edgeanimate/api/current/index.html
    BTW, you should use the capitalized "Stage" to add it to the Stage - the lower case stage has a special meaning with Animate and might not give you what you want..
    sym.createChildSymbol("gardentoxins", "Stage");
    In the symbol itself, create a click event on a container div, then:
    sym.deleteSymbol();
    That being said, you don't need to dynamically create and delete an object.  What you can do is to use hide() and show() on an element and use the coordinates of your click to change the CSS value of top/left of this object so that you don't have to do the object management I highlighted above.
    Hope that points you in the right direction.
    -Elaine

  • Dynamically Load Thumbnails To Horizontal Movieclip?

    I'd like to dynamically load thumbnails into a horizontal movieclip at the bottom of an image gallery to then allow me to load an image by clicking the thumbnails. I found a tutorial to help me load the thumbnails to the stage but I am not sure how to load them into the thumbs movieclip. Here is the code I am using:
    var imageLoader:Loader;
    var xml:XML;
    var xmlList:XMLList;
    var xmlLoader:URLLoader = new URLLoader();
    xmlLoader.load(new URLRequest("xml/murals.xml"));
    xmlLoader.addEventListener(Event.COMPLETE, xmlLoaded);
    function xmlLoaded(event:Event):void
        xml = XML(event.target.data);
        xmlList = xml.children();
        for(var i:int = 0; i < xmlList.length(); i++)
            imageLoader = new Loader();
            imageLoader.load(new URLRequest(xmlList[i].attribute("thumb")));
            imageLoader.x = i * 175 + 25;     // <----- Also, I don't seem to understand how to space the thumbnails using this code.
            imageLoader.y = 5;
            addChild(imageLoader);
    Thanks in advance!
    -Dan

    I wasn't sure if I should make a new discussion for this or not so I'm just going to post it here.
    Alright. I finally found a tutorial that works for what I am trying to do. The thumbs load on a grid and when I click on the thumb they load in the loader. Now I am having trouble removing them. The tutorial has the remove function on the loaded large image so when you click that it removes itself. I would like so that when you click on the a thumb the current image will unload and the thumb that is clicked on will load but can't figure out how to get it to do that. I figured I'd just add a CLICK listener for the "removeFull" function to the "callFull" function but I think it cancels itself out.
    Here is the code I am using: (the code to load and unload is toward the bottom)
    stop();
    var columns:Number = 2;
    var my_x:Number = 25;
    var my_y:Number = 75;
    var my_thumb_width:Number = 65;
    var my_thumb_height:Number = 65;
    var my_images:XMLList;
    var my_total:Number;
    var container_mc:MovieClip;
    var x_counter:Number = 0;
    var y_counter:Number = 0;
    var myXMLLoader:URLLoader = new URLLoader();
    myXMLLoader.load(new URLRequest("xml/gallery.xml"));
    myXMLLoader.addEventListener(Event.COMPLETE, processXML);
    function processXML (e:Event):void{
        var myXML:XML = new XML(e.target.data);
        my_images = myXML.IMAGE;
        my_total = my_images.length();
        createContainer();
        callThumbs();
    function createContainer():void{
        container_mc = new MovieClip();
        container_mc.x = my_x;
        container_mc.y = my_y;
        addChild(container_mc);
    //The large image loads when the thumb is clicked on.
        container_mc.addEventListener(MouseEvent.CLICK, callFull);
        container_mc.buttonMode = true;
    function callThumbs():void{
        for (var i:Number = 0; i < my_total; i++){
            var thumb_url = my_images[i].@THUMB;;
            var thumb_loader = new Loader();
            thumb_loader.load(new URLRequest(thumb_url));
            thumb_loader.contentLoaderInfo.addEventListener(Event.COMPLETE, thumbLoaded);
            thumb_loader.name = i;
            thumb_loader.x = (my_thumb_width+25)*x_counter;
            thumb_loader.y = (my_thumb_height+25)*y_counter;
            if (x_counter+1 < columns){
                x_counter++;
            } else {
                x_counter = 0;
                y_counter++;
    function thumbLoaded(e:Event):void{
        var my_thumb:Loader = Loader(e.target.loader);
        container_mc.addChild(my_thumb);
    //This function loads the large image.
    function callFull(e:MouseEvent):void{
        var full_loader:Loader = new Loader();
        var full_url = my_images[e.target.name].@FULL;
        full_loader.load(new URLRequest(full_url));
        full_loader.contentLoaderInfo.addEventListener(Event.INIT, fullLoaded);
    //This function centers the large image in the gallery loader.
    function fullLoaded(e:Event):void{
        var my_loader:Loader = Loader(e.target.loader);
        MovieClip(parent.parent).gallery.addChild(my_loader);
        my_loader.x = (MovieClip(parent.parent).gallery.width - my_loader.width)/2;
        my_loader.y = (MovieClip(parent.parent).gallery.height - my_loader.height)/2;
    //The large image unloads when it is clicked on.
        my_loader.addEventListener(MouseEvent.CLICK,removeFull);
    //This function removes the loaded image from the gallery loader.
    function removeFull(e:MouseEvent):void{
        var my_loader:Loader = Loader (e.currentTarget);
        my_loader.unload();
        removeChild(my_loader);

  • How to unload dynamically loaded modules?

    Hi,
    I have a problem with unloading module, which I loads dynamically.
    Here is a fragment my code:
    <TitledWindow .......creationComplete="init()"/>
    <mx:Accordion id="lista_ryzyk">
    </mx:Accordion>
    <mx:Script>
    public function init():void
    {    CairngormEventDispatcher.getInstance().addEventListener(LoadRisksEvent.EVENT_RESULT, populateAccordion);
    public function populateAccordion(event:CairngormEvent):void
         lista_ryzyk.removeAllChildern();
         for (i in risks)
              var m:ModuleLoader = new ModuleLoader();
              m.url = path_to_module;
              m.label = module_label;
              m.loadModule();
         lista_ryzyk.addChildAt(m,Number(i));
    </mx:Script>
    The modules loads fine. Each module adds own eventListener for some event. It works fine, but ONLY for first time. For next invoke populateAccordion function, the modules loads, but don't reacts for event. I investigate !!! that for events reacts that modules, which was loaded for the first time!!! How to remove it????

    Using array, didn't solve my problem, but it is possible that I'm doing something wrong.
    I still can't catch event in second time loaded module :-((( I have tried to solve this problem from wednesday! it goes me crazy!
    Could you, or anybody, try to inspect my code and help me? I have no idea how to manage it.
    I know exactly what is wrong, but I can't improve that. In module's creationComplete function I display the UID of this module, and in body of eventHandler function I do the same. In case of FIRST time  the displayed UID are the same, but when I load the module second time, the UID of the loaded module displayed in creationComplete function is new, but the UID displayed in handler function is the same as the first loaded module. So my event is catch by the wrong modul, and I don'tknow how to change it, how to process event in my newly loaded module.

  • How to dynamically load images into Flash

    I have a movie clip on the stage that I want to dynamically
    load images into (that constantly change), how would I go about
    doing this? Thanks.

    Use the Loader class to load in images.
    Then use addChild to add the Loader class into your MovieClip
    on the stage.
    As far as &amp;quot;constantly change&amp;quot; what
    do you mean by that? You could use setInterval, ther enterFrame
    event, or any other means to trigger a new image to be loaded into
    the Loader instance.
    Finally, you can use the Tween class to create some nice
    effects for the images (fade it, blur in, photo blend, masks,
    etc)

  • Is there a way to clear ALL event listeners, stop all movie clips, etc?

    Is there a syntax for this?
    I have a movie that has 15 frames. Each frame has embedded movie clips within movie clips, tons of animations and event listeners. None is needed except when they are on the stage, on the frame. However, the animations continue even when the frame is left.
    For instance, I have a frame that has a dynamically rendered animation of leaves falling from a tree. When the frame is left, the leaves continue to fall.
    There are many instances of this type of thing happening.
    Ideally, I would love to just be able to clear everything when a new frame is loaded, since none of the animations or event listeners need to carry over from one frame to another.
    Is there a way to do this without the thousands of lines of code it would take to manually remove every single animation and event listener and sound, etc, from the stage?
    Thanks so much!!
    Amber

    you have to manually do that.
    or, you could convert each frame to a swf.  load each swf when needed and, if you're publishing for fp 10+, you can apply unloadAndStop() to kill all streams in the loaded swf and ready those assets for gc.

  • Does removeChild remove the object's event listeners?

    Hi
    If you dynamically create a parent movieclip, and dynamically add a color picker to each clip, and add an event listener for each color picker, does a removeChild on the parent movieClip remove event listeners belonging to any of it's children?
    Thanks
    Shaun

    Ahh - thanks Ned
    Is there any software you could recommend that monitors and shows you what or how many event listeners are open, memory consumption etc, to help you to trim the fat from your coding?
    Thanks
    Shaun

  • Spry Tabbed panels + Progressive Enhancement and Dynamic Loading of Content With Spry

    Is there any way to combine tabbed panels together with "Progressive Enhancement and Dynamic Loading of Content With Spry"?
    Visit: http://labs.adobe.com/technologies/spry/articles/best_practices/progressive_enhancement.ht ml#updatecontent
    And click on the "Using Spry.Utils.updateContent()"
    The 3rd example shows how to use a fade transition whenever the content changes.
    I already have tabbed panels. My menu contains buttons (on tabs) and my Content div contains the panels.
    Tabs code;
    <ul class="TabbedPanelsTabGroup">
              <li class="TabbedPanelsTab">
                   <table class="Button"  >
                        <tr>
                        <td style="padding-right:0px" title ="Home">
                        <a href="javascript:TabbedPanels1.showPanel(1);" title="Home" style="background-image:url(/Buttons/Home.png);width:172px;height:75px;display:block;"><br/></a>
                        </td>
                        </tr>
                   </table>
              </li>
    etc
    etc
    etc
    and the panel code:
    <div class="TabbedPanelsContent" id="Home">
         CONTENT
    </div>
    I hoped i can use the example code from the link into my tabbed panels.
    I thought this code:
    onclick="FadeAndUpdateContent('event', 'data/AquoThonFrag.html'); return false;"
    could be added to the tab code like this:
    <a href="javascript:TabbedPanels1.showPanel(1);" onclick="FadeAndUpdateContent('event', 'data/AquoThonFrag.html'); return false;" title="Home" style="background-image:url(/Buttons/Home.png);width:172px;height:75px;display:block;"><br/></a>
    But the content doesnt fade...
    I know i need to change the header etc.
    The following is from the link:
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml" xmlns:spry="http://ns.adobe.com/spry">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>Aquo Events</title>
    <script src="../../../includes/SpryEffects.js" type="text/javascript"></script>
    <script src="../../../includes/SpryData.js" type="text/javascript"></script>
    <script type="text/javascript">
    <!--
    function FadeAndUpdateContent(ele, url)
    try {
         Spry.Effect.DoFade(ele,{ duration: 500, from: 100, to: 0, finish: function() {
              Spry.Utils.updateContent(ele, url, function() {
                        Spry.Effect.DoFade(ele,{ duration: 500, from: 0, to: 100 });
    }catch(e){ alert(e); }
    -->
    </script>
    <style type="text/css">
    /* IE HACK to prevent bad rendering when fading. */
    #event { background-color: white; }
    </style>
    </head>
    So i changed my header etc, put the SpryEffects.js and SpryData.js into position and nothing changed...
    Is there a way to keep my tabbed panel (or change as less as possible) and let
    A. The fade work
    B. The loading work.
    The problem now is that it loads all pages instead of only the home. Therefore i wanted this Progressive Enhancement.
    And the fading part is just because its nice...

    It doesnt show in the post but off course i changed this link;
    "data/AquoThonFrag.html"
    into;
    "javascript:TabbedPanels1.showPanel(1);"
    I must say i dont know if this even works...

Maybe you are looking for

  • Steps to create your own self signed certificate with java plugin working

    You need two tools that comes with your jdk which are keytool and jarsigner. Steps explain below in detail. Don't use netscape signtool, it will NEVER work! * keytool -genkey -keyalg rsa -alias tstkey -keypass 2br2h2m -dname "cn=Test Object Signing C

  • Can i set up standby in Single system

    Hi all, Can i setup the standby in single system? If yes, my primary DB in C:\ORACLE i want to set up my standby DB in E:\ORACLE. I am trying to do the setup, but iam getting the problem at standby control file. 1) I cann't give the same name for the

  • Loading EJB problem with deployejb !

    I am working with Oracle 8.1.5 and jdk 1.1.6, when I am running the deployejb tool with the HelloWorld example of the demo directory, I have a problem when loadind EJB files into the database: deployejb -v -u workuser ... done Compiling Stubs...done

  • Small caps - is there a way to change size ratio of lower to upper case?

    I am using Adobe InDesign CS4 and one problem I've had is that when I select Small Caps on the character styles panel, lower case characters are about 60% the size of upper case characters. I'd like this to be more around 80% in my document. I don't

  • Scripting using RealBasic

    Has anyone tried scripting in RealBasic on Windows? I am trying to Open a document and set the size for the TextFrame but it just won't have it.