Why do button functions included in external actionscript not persist across frames?

this one drives me nuts!
if i include an external actionscript file in frame one of my
movie, then [as you'd expect] all the functions, global variables
etc contained in that external AS file are available throughout my
movie - with one notable exception.
if i add a button to the stage - in a frame other than frame
one - whose onRelease handler is defined in the external AS, the
function is not called when the button is clicked - i have to
re-include the external AS file again on the frame in which the
button resides, in order for the buttons function to be called.
anyone know why this is - and if there's a way round it?
how come all the other functions in the AS persist across all
frames and all timelines in the movie, but the button handlers only
seem to be available on the actual frame in which the AS file is
included?
download
example

I think you and I are dealing with similar issues and the
root cause is referred to as "scope." The only difference between
your and my problems is that your code is in an external as file
and mine is on the timline. But in both instances, code that should
work doesn't. Robert Reinhardt has covered this in an article at
http://www.communitymx.com/content/article.cfm?cid=8E4DF.
He is the author of the Flash Actionscript Bible series and so
knows what he is talking about. I have been studying it for an hour
and darn if I can understand the second page of it. I've asked for
help myself about this at
http://www.kirupa.com/forum/showthread.php?t=248316.

Similar Messages

  • Calling a function in an external actionscript

    Hi. First of all I'd like to put my hands up and say that what I know about Flash is antiquated (I used to work with Flash 4 / 5), and have now been thrown into the deep end, as it were.
    I have an application that has a button component. In an external actionscript file there's an event listener that calls a function when this button is pressed. I want to replace the button with a graphic that switches according to whether the button is 'on' or 'off'. I've created a movie clip that cycles back and forth between the on and off states when clicked, but the trouble I'm having is getting it to call the function. I have no idea how to do it, other than to just include function_name(); (or call.function_name();) in the onRelease handler (which doesn't work). Is it possible to use event listners for movie clips (rather than components?) Or else how can I call this function? It should be really simple and I'm tearing my hair out trying to get it to work! The function is declared 'public', by the way...
    Oh yes, this is ActionScript 1 (I think...)
    Eternal thanks and gratitude to anyone who can help me...

    Do you mean to copy it here, or copy it into the fla? I've already tried doing the latter, which doesn't work - the script imports other external as files and I think that that's messing things up. The function only seems to work when it's located in this external file. The function I'm trying to call is
    public function toggleAudio() {
           //if (btnAudio.label == "Sound Off") {
           if (_root.audio == "mute" or btnAudio2.label == "Sound Off") {
               trace("toggleAudio AUDIO: Off");
               //btnAudio.label = "Sound On";
               _root.audio = "unmute";
                         // stop recieving audio from in stream
               ServiceLocator.getInstance().getService("nsService").returnInStream().receiveAudio(false) ;
               // stop sending audio on out stream
               ServiceLocator.getInstance().getService("nsService").returnOutStream().attachAudio(null);
                     } else {
               trace("toggleAudio AUDIO: On");
               btnAudio2.label = "Sound Off";
               _root.audio = "mute";
                         // start recieving audio from in stream
               ServiceLocator.getInstance().getService("nsService").returnInStream().receiveAudio(true);
               // start sending audio on out stream
               ServiceLocator.getInstance().getService("nsService").returnOutStream().attachAudio(Servic eLocator.getInstance().getService("camService").returnMic());
    The bit at the beginning where I've commented some stuff out is where I've been trying out different things to get it to work.
    For all intents and purposes though the function could be
    public function please_work() {
    trace("I work!");
    All I need is for a way to call this from the main flash movie

  • Why item button only show #APP_IMAGES# image but not #WORKSPACE_IMAGES#?

    Hi All, I have a item button with Button display attributes - Style as Image. I don't know how come it can only display #APP_IMAGES# image but not #WORKSPACE_IMAGES# image. Please help... Thank you in advance. :)
    Chris

    Hi All, I have a item button with Button display attributes - Style as Image. I don't know how come it can only display #APP_IMAGES# image but not #WORKSPACE_IMAGES# image. Please help... Thank you in advance. :)
    Chris

  • Why won't iPhoto on an external HD not recognize video from the iPhone?

    When the iPhoto library is located on the iMac internal HD, all photos and videos from my iPhone 4S are imported without issue.  When the library is located on an external HD, however, the photos are imported, but the videos are not.  An error message at the end of the import indicates the .mov video files are an "unrecognized format."

    Anyway, good questions.  The drive is, indeed, Mac OS extended (journaled).  It is physically connected to another iMac on my ethernet network which shares the drive (and others) with my "working" Mac located in my office.  The drive, as well as another for iTunes, are mounted on the office Mac.  The iPhoto and iTunes libraries were created on them in the usual fashion.  Adding to those libraries from my iPhone or, say a CD inserted into the office Mac, has not been a problem, EXCEPT for importing video from the iPhone 4S.  I have not tried other camera devices.  This is true if I use Image Capture as the import "tool" stipulating iPhoto on the EHD as the destination. 
    As I said, importing to an iPhoto library resident on the Mac internal HD is NO problem, only the external drive.
    LL

  • Export for actionscript - Not in first frame

    Just a simple question.
    Don't need to know if it works or not I have tested it. What
    I want is to understand. Here it is:
    If I use the Export for actionscript and I unselect the
    Export in first frame, the item that will be linked by the ID in
    the library must appear on the timeline. Normally it must be on a
    frame that has played. IE frame 3 the item is there so I can use it
    from the frame 3 to the last frame. This is how it works for the
    _root. If I'm in a clip, the code can be on the first frame with a
    stop. That means that the Item is on the second frame and has not
    displayed, but it is accessible by the code.
    Why?
    Why on the root the item must appear on the frame where the
    code is or before the code, but if in a clip, the code can works
    even the item reside on a later frame that will never display
    because there is a stop on the first one?
    Tanx for your help to understand!

    I think that this is probably because of how flash streams
    content. In order for flash to play frame 2 on the timeline, it
    COMPLETELY loads all the code and assets for that frame (but not
    frame 3) and then 'plays' that frame. Therefore on the main
    timeline, code on frame 2 can't access exported clips from frame 3.
    However, if your movie clip is (for example) on frame 4,
    flash will stream/load everything (including your complete move
    clip) when the play head reaches that frame, so all assets within
    that frame are available because in order to even 'play' frame 4,
    flash has had to load the entire movie clip contents.

  • External Actionscript File not being Included

    Odd problem:
    Myself and a colleague are working on a project. We're both
    using Flash 8. We've both downloaded the latest Flash player.
    The project involves a series of perfume bottles, all lined
    up in a row. When you press a key on the keyboard, the associate
    bottle enlarges and some info on it appears. At the same time the
    other bottles fade out (an alpha change).
    The alpha change is driven using an external actionscript
    file, which is called (#include) at the top of the first line of
    script in the ‘main’ movie.
    The problem is, when I publish the swf file, the alpha change
    doesn’t work. When my colleague publishes it, it works. Why
    is this? It’s almost as if in publishing from my computer,
    the external .AS file is being ignored.
    I’ve tried calling the .AS file using a full path to
    the file. No change.
    I’ve tried uninstalling and reinstalling the Flash
    player, and older version of the player. No change.
    Here’s something else that’s odd: I’ve
    tried copying all the script from the external .AS file and
    embedding it into the main movie. No change. Is it that the
    publishing from my computer is corrupted? Other things I’ve
    published recently have worked fine?
    Any ideas?

    Yes, I've opened the AS file, and it seems ok. I've also had
    it sent to me a couple of times in case it got corrupted in
    transit.
    I've also tried copying the script from the AS file and
    embedding it into the 'main' movie at the #include statement (and
    removing the #include statement) so it doesn't have to look for the
    AS file, but this hasn't helped.
    I'll try making a different AS file with the trace statement
    you suggested, but I have other movies that call external AS
    statements, and they work.
    We're both running XP Pro w/ SP2.

  • Why do some functions such as buttons and menues not work on certain sites in firefox

    buttons and functions on certain sites do not work in firefox 10

    * "Clear the Cache": Tools > Options > Advanced > Network > Offline Storage (Cache): "Clear Now"
    * "Remove the Cookies" from sites that cause problems: Tools > Options > Privacy > Cookies: "Show Cookies"
    Start Firefox in [[Safe Mode]] to check if one of your add-ons is causing your problem (switch to the DEFAULT theme: Tools > Add-ons > Themes).
    See [[Troubleshooting extensions and themes]] and [[Troubleshooting plugins]]

  • 'Basic' external actionscript file/class usage

    Hey All,
    I'm a bit baffled by something that should, in my humble opinion, be a piece of cake...
    The setup is really easy. A simple application with a single textinput, a button and a text component.
    When the button is clicked a function is called that sets the text from the inputfield to the text component.
    code:
    <?xml version="1.0" encoding="utf-8"?>
    <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute">
        <mx:Script>
            <![CDATA[
                public function click(inputText:String):void {
                    outPutTxt.text = inputText;
            ]]>
        </mx:Script>
        <mx:TextInput x="10" y="10" id="inputTxt"/>
        <mx:Button x="178" y="10" label="Button" id="Btn" click="{click(inputTxt.text)}"/>
        <mx:Text x="251" y="12" text="Text" id="outPutTxt"/>
    </mx:Application>
    As I said, really easy.
    What I want to do is put the function 'click' into an external actionscript file or class. And still be able to, from within the external file, modify the outPutTxt stuff.
    I'm aware that I could create a public bindable variable inside of the external file and then bind the outPutTxt to that variable, but I would really like to be able to 'simply' force the value...
    Is that possible? If yes: how plix
    If it's not possible, I'd like to know as well! And in that case, how would I then re-use the same instance of a class/file in multiple seperate components? Say I got a 'login' thingie where a user logs in (data stored externally in a seperate actionscript file/class) and I want to re-use that information on other pages... Or is this done automatically?
    Any and all comments/answers are higly appreciated!
    Pieter

    Hey Levancho,
    thanks for your answer!! Much appreciated.
    However, the code you proposed threw an error...
    Errormessage:
    ReferenceError: Error #1069: Property outPutTxt not found on controls.Control and there is no default value.
        at controls::Control/btnClick()[C:\...\FlexTest_03\src\controls\Control.as:13]
        at FlexTest_03/__Btn_click()[C:\...\FlexTest_03\src\FlexTest_03.mxml:11]
    So I tried something else where I bind the text in my OutPutTxt to a variable inside of the external class file.
    Code:
    Class:
    package controls
        public class Control
            [Bindable]
            public var outPutText:String = "";
            public function Control()
            public function btnClick(inputText:String):void {
                this.outPutText =  inputText;
    Mxml:
    <?xml version="1.0" encoding="utf-8"?>
    <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute">
        <mx:Script>
            <![CDATA[
                import controls.Control;
                [Bindable]
                private var control:Control = new Control();
            ]]>
        </mx:Script>
        <mx:TextInput x="10" y="10" id="inputTxt"/>
        <mx:Button x="178" y="10" label="Button" id="Btn" click="{control.btnClick(inputTxt.text)}"/>
        <mx:Text x="251" y="12" id="outPutTxt" text="{control.outPutText}"/>
    </mx:Application>
    And this basically did what I wanted to do... so I just need to do some major binding between my application and the classes I'll be using for my business logic.
    Now for something else entirely...
    Is there a way for me to pass the instance of my class between flex components?
    Pieter

  • Re: [iPlanet-JATO] Back Button functionality

    Hi Mike,
    Our test environment does not include proxy server.
    regards,
    syam.
    Please respond to [email protected]
    cc:
    Subject: Re: [iPlanet-JATO] Back Button functionality
    Guys,
    Please clarify something for me, the JATO code is commented as follows
    protected void addResponseHeaders(RequestContext requestContext)
    // These values should make any proxy between the client and
    // server avoid caching, and ensure that pages from one user
    // can never be seen by another user (if they're cached anyway)
    requestContext.getResponse().addHeader("Pragma","no-cache");
    requestContext.getResponse().addHeader
    ("Cache-Control","private");Yet you make no mention of whether your test environment includes a Proxy
    Server, or does your browser
    go directly to the Application Server's web server?
    Can you clarify, please?
    ----- Original Message -----
    From: <syam_reddy@p...>
    Sent: Wednesday, April 25, 2001 2:59 PM
    Subject: [iPlanet-JATO] Back Button functionality
    >
    Hi,
    We observed the following difference in behaviour between JATO pages
    and NetD served pages.
    We have the following scenario. User will login to the
    site. After login he will get a frame set. This frame set has threeframes.
    Top and bottom frames are used for navigation (to switch between various
    sections on the site.) .The middle frame(main frame) shows the actual
    content. When the the frame set gets loaded main frame shows page1. User
    will click on a link on page1. Page 2 will be loaded in main frame. Atthis
    point if the user clicks on back button , with migrated application(JATO
    pages) the following message appears in the main frame.
    In Netscape Communicator 4.61 the following message appears in the main
    frame :
    Data Missing
    This document resulted from a POST operation and has expired fromcache.If
    you wish you can repost the form data to recreate the document by
    presenting the reload button.
    In IE 4.72/5.5 the following message appears in the main frame:
    Warning : Page has Expired
    The page you requested was created using information you submitted in a
    form.This page is no longer available.As a security precaution, Internet
    Explorer does not automatically resubmit your information for you. To
    resubmit your information and view the web page click teh refresh button.
    However, in the NetD site page1 will appear in main frame.
    How do we mimic the NetD behaviour with the migrated
    applications ?
    We think the above behaviour with migrated Apps, is due to the
    headers that are get set in Application ServletBase , see the following
    code snippet :
    protected void addResponseHeaders(RequestContext requestContext)
    // These values should make any proxy between the client and
    // server avoid caching, and ensure that pages from one user
    // can never be seen by another user (if they're cached anyway)
    requestContext.getResponse().addHeader("Pragma","no-cache");
    requestContext.getResponse().addHeader
    ("Cache-Control","private");
    If we comment the above code , we were able to mimic theNetD
    behaviour. Are there any alternatives/thoughts on how to mimic the NetD
    behaviour ?
    Thanks in Advance,
    syam&ravi.
    [email protected]
    [email protected]

    OK, here's what I'm trying to do: We have, like you said, a menu
    page. The pages that it goes to and the number of links are all
    variable and read from the database. In NetD we were able to create
    URLs in the form
    pgXYZ?SPIDERSESSION=abcd
    so this is what I'm trying to replicate here. So the URL that works
    is
    pgContactUs?GXHC_GX_jst=fc7b7e61662d6164&GXHC_gx_session_id_=cc9c6dfa5
    601afa7
    which I interpreted to be the equivalent of the old Netd way. Our
    javascript also loads other frames of the page in the same manner.
    And I believe the URL-rewritten frame sources of a frameset look like
    this too.
    This all worked except for the timeout problem. In theory we could
    rewrite all URLs to go to a handler, but that would be...
    inconvenient.

  • Why can't I see my external hard drive, Intel iMac / 500 GB, G-Drive

    Why can't I see my external hard drive?  I have a new iMac, Intel based i5, running Lion (2-3 months old).  I have a 500 GB G-Drive external hard drive that has showed up when connected to my iMac for the past 2-3 months.  Now it's gone.  It's NOT visible when using Disk Utilities.  I have all of the radio buttons chosen in the Finder Preferences.  I've unplugged and replugged in the drive, have switched the cable ports and have switched firewire cable.  The G-Drive powers up and whirls, so I don't believe the problem is with the drive. Yes, I set my Preferences to make sure ALL disk types are visible.  I've restarted my iMac on a number of occations.  I rest my SMC by totally unplugging my iMac for a minute, then plugging it back in. Any suggestions?

    Unplug the HD, Zap the PRAM, reconnect the HD, power it up, and see if that fixes the problem. If not, then maybe the HDs bitten the dust. Try on another computer to verify.

  • How to import classes from an external actionscript file

    This is driving me crazy, I've been trying to resolve this on my own for ages, and I've reviewed a lot of different materials, but I still can't seem to just import some external actionscript classes correctly.
    I'm using Flash Builder 4 with the Flex 4 SDK on mac osx 10.6
    the class I'm trying to import (I'll call it DesiredClass) is in a folder like this
    /libraries/com/foreignproject/com/foreignproject/DesiredClass.as
    within the class itself, the package declaration looks like this (I left all the guts out for clarity):
    package com.foreignproject
        import flash.display.Sprite;
        public class DesiredClass extends Sprite
            public function DesiredClass()
    I'm working on a totally different actionscript file at
    /Users/username/Documents/Adobe Flash Builder 4/TestProject/src/TestProject.as
    in this file I try to import the DesiredClass:
    package
         import com.foreignproject.DesiredClass;
         import flash.display.Sprite;
         public class TestProject extends Sprite
              public function TestProject()
              var neatClass:DesiredClass = new DesiredClass();
    And then I try to add the class I want to the source path.
    I've tried adding each folder to the source path separately:
    /libraries/com/foreignproject/com/foreignproject/DesiredClass.as
    /libraries/com/foreignproject/com/foreignproject/DesiredClass.as
    /libraries/com/foreignproject/com/foreignproject/DesiredClass.as
    /libraries/com/foreignproject/com/foreignproject/DesiredClass.as
    /libraries/com/foreignproject/com/foreignproject/DesiredClass.as
    If I choose the libraries folder or either of the com folders then an error shows up in theTestProject.as file, saying:
    Definition com.foreignproject:DesiredClass could not be found.
    But f I choose either of the foreignproject folders then an error shows up in theDesiredClass.as file saying:
    a file found in a source-path must have the same package structure 'com.foreignproject', as the definition's package, ".
    What am I doing wrong? Please help. I bought a book on actionscript, started doing the flex-in-a-week series, read numerous online discussion boards, and I still can't import these classes.
    Thanks in advance.

    I don't know if this method is supported anymore but you can give it a try.
    If you backed up bookmarks in IE using the following directions, you should be good!
    *In IE, "File -> Import and Export -> Export Cookies".
    *Open newly exported "cookies.txt" in a text editor and put a period before every line that starts with a domain. So a line starting with <b>altavista.com TRUE / FALSE 1388491200 AV_ALL 1</b> will become <b>.altavista.com TRUE / FALSE 1388491200 AV_ALL 1</b>
    *Then, move the "cookies.txt" file to your profile folder.
    You can get to the Profile folder two ways
    *Help > Troubleshooting Information > Profile Directory > Show Folder
    or
    *Go to '''about:support''' and click Show Folder next to Profile Directory.

  • Frustrated - trying to make button function

    Hello,
    Okay, here's an example of what I want to do on this site:
    http://www.templatemonster.com/flash-templates/8549.html
    I am creating my first website in Flash and need help with my
    Actionscript. I made three buttons, which are inside my intro page
    movieclip called mcIntro. When you click the buttons, I want it to
    take them to a frame label on the main timeline (in the case below,
    "print"). Then I want the movieclip that's on the "print" section
    to go and play an animation with the frame labeled "in". Then,
    depending on whether the web section, print section, or main
    section is visible, I want the section they're leaving to go to the
    "out" animation. Here's what I did, and it didn't work.
    mcIntro.bPrint.onRelease = function() {
    _root.gotoAndPlay("print");
    mcPrint.gotoAndPlay("in");
    if (mcWeb._visible) {
    mcWeb.gotoAndPlay("out");
    if (mcIntro._visible) {
    mcIntro.gotoAndPlay("out");
    Help is appreciated, thanks!

    This sounds like the same problem as in this earlier post today... not properly naming the button instance...
    http://forums.adobe.com/thread/856044?tstart=0

  • How do I get the layout to MATCH the options set for Google Toolbar (why do buttons I have DESELECTED in the Options interface persist in appearing)? I have no interest in USA, News, Orkut, et cetera.

    Google Toolbar: Manage> Google Toolbar Options> Buttons> USA [DESELECT] does not function properly, and persists in appearing, despite the empty Check-Box. Why is the option there if it does not work? Have these coders ever heard of Testing Before Release? While I cannot claim familiarity with the coding in Firefox, I AM an application and web writer (¡Hasta 1984!); this is something every Programming 101 student learns if it wishes to pass the course, let alone become professionally employed in such a field.

    I ran into the problem you have after trying to update to 7.1.2 the phone updated, but got stuck in recovery mode, and none of the reset methods worked. I did some searching and came up with a simple method, and it got me out of the loop.
    Once i used this app, My phone booted and The update was in place.
    http://jaxov.com/2010/05/recboot-iphone-recovery-mode/

  • Button Function Failure on Adobe Content Viewer

    Why do the button functions work well the first time I view them on my iPad's Adobe Content Viewer but do not function properly in subsequent viewings?
    For example, the next page buttons work flawlessly during the first viewing on the iPad. But from the second time they functions awkwardly. The Next page button on Page 1 stops functioning. The one on Page 2 takes me back to Page 1.

    Same issue-- and it's been  a few weeks now.  As far as I can tell it is a waiting issue
    This is from Page 68 from USING DIGITAL PUBLISHING SUITE
    help.adobe.com/en_US/digitalpubsuite/.../digitalpubsuite_help.pdf
    Last updated 3/23/2012
    Use the iPad Viewer to preview content
    The Adobe Content Viewer for the iPad is a generic version of the viewer used for testing the digital content you create on the iPad. The iPad viewer is updated whenever the Folio Producer tools are updated.
    Note: However, when a new set of tools is released, folios you create with those tools may not work properly until Apple approves the new viewer version. If you try to open the folio, a “Please update your app” message appears. If you have a Professional or Enterprise account, you can create a custom version of the Adobe Content Viewer. See
    “Create a custom Adobe Content Viewer for iPad” on page
    98. Otherwise, hold off on updating the tools or use the Desktop Viewer until Apple approves the updated viewer.

  • Button function failure

    Why do my button functions work perfectly on my iPad2 Adobe Content Viewer the first time and then do not function at all in subsequent viewings. For example, the next page button ceases functioning after the first viewing. On page 2, the next page button returns me to Page 1.

    Hi lhprod,
    I was looking at this document:
    http://helpx.adobe.com/digital-publishing-suite/help/supported-interactivity-features.html
    Note in the Interactivity features not supported section the reference to button actions. I think this is not a supported feature.
    -Dave

Maybe you are looking for