Actionscript newbie

i'm exploring actionscript for the first time and was
exploring some of the templates that Flash offers. I came across a
slide animation template with this code in the first frame. can
anyone explain it to me?
// If not defined yet,
if (isLoaded == undefined) {
// Routine to move playhead to a new frame
var updateFrame = function (inc) {
var newFrame = _currentframe + inc;
gotoAndStop(newFrame);
if (_root._currentframe == 1) {
backBtn._alpha = 50;
backBtn.enabled = false;
} else {
backBtn._alpha = 100;
backBtn.enabled = true;
if (_root._currentframe == _root._totalframes) {
forwardBtn._alpha = 50;
forwardBtn.enabled = false;
} else {
forwardBtn._alpha = 100;
forwardBtn.enabled = true;
// When the forward button is pressed
forwardBtn.onPress = function () {
updateFrame(1);
// When the back button is pressed
backBtn.onPress = function () {
updateFrame(-1);
// When the keyboard keys are pressed
var keyListener = new Object();
keyListener.onKeyDown = function () {
if (Key.isDown(37)) {
// Left
updateFrame(-1);
} else if (Key.isDown(38)) {
// Up
updateFrame(-(_currentframe-1));
} else if (Key.isDown(39)) {
// Right
updateFrame(1);
} else if (Key.isDown(40)) {
// Down
updateFrame(_totalFrames + 1);
Key.addListener(keyListener);
// Call updateFrame at first to get button states correct at
start
updateFrame();
// Set loaded flag to prevent redefinition
this.isLoaded = true;
stop();

The isLoaded variable is because the frame containing the
code should only
play once and in case the playback head crossed the frame the
code will not
play twice.
The updateFrame function sets the appearance of UI buttons
based mostly on
the frame number.
The other functions are attached to buttons or keys to handle
their
interaction and all seem to call updateFrame.
Lon Hosford
www.lonhosford.com
Flash, Actionscript and Flash Media Server examples:
http://flashexamples.hosfordusa.com
May many happy bits flow your way!
"Brhaynes75" <[email protected]> wrote in
message
news:[email protected]...
> i'm exploring actionscript for the first time and was
exploring some of
> the
> templates that Flash offers. I came across a slide
animation template with
> this
> code in the first frame. can anyone explain it to me?
>
>
> // If not defined yet,
> if (isLoaded == undefined) {
>
> // Routine to move playhead to a new frame
> var updateFrame = function (inc) {
>
> var newFrame = _currentframe + inc;
> gotoAndStop(newFrame);
>
> if (_root._currentframe == 1) {
> backBtn._alpha = 50;
> backBtn.enabled = false;
> } else {
> backBtn._alpha = 100;
> backBtn.enabled = true;
> }
> if (_root._currentframe == _root._totalframes) {
> forwardBtn._alpha = 50;
> forwardBtn.enabled = false;
> } else {
> forwardBtn._alpha = 100;
> forwardBtn.enabled = true;
> }
> }
>
>
> // When the forward button is pressed
> forwardBtn.onPress = function () {
> updateFrame(1);
> }
>
> // When the back button is pressed
> backBtn.onPress = function () {
> updateFrame(-1);
> }
>
> // When the keyboard keys are pressed
> var keyListener = new Object();
> keyListener.onKeyDown = function () {
> if (Key.isDown(37)) {
> // Left
> updateFrame(-1);
> } else if (Key.isDown(38)) {
> // Up
> updateFrame(-(_currentframe-1));
> } else if (Key.isDown(39)) {
> // Right
> updateFrame(1);
> } else if (Key.isDown(40)) {
> // Down
> updateFrame(_totalFrames + 1);
> }
> }
> Key.addListener(keyListener);
>
>
> // Call updateFrame at first to get button states
correct at start
> updateFrame();
> }
>
> // Set loaded flag to prevent redefinition
> this.isLoaded = true;
> stop();
>

Similar Messages

  • ActionScript Newbie: Learn AS2 or AS3?

    I'm wanting to get into Flash development, and I'm trying to
    work out which language to learn. Do I take this opportunity to
    skip straight to the newer ActionScript 3? Or do I learn the
    "simpler" AS2, and migrate once I've mastered it?
    I'm hoping to use my development skills mainly for animation
    (not fully blown Flex apps).
    Any help appreciated. Thanks very much.

    There is definitely a much much higher learning curve for AS3
    and learning
    resources (as mentioned) are limited. You may want to
    consider your own
    skills as a programmer before deciding to jump into AS3.
    Starting small
    with AS1 or even AS2 basics might be easier until you get
    familiar enough
    with AS to get into AS3 (which is still fairly new and not
    yet widely used).
    "David Stiller" <[email protected]> wrote in
    message
    news:[email protected]...
    > mambo_06,
    >
    >> Excellent, thanks. I'll probably invest in a copy of
    Flash
    >> CS3 (I've got version 8 at the moment).
    >> Any recommendations on books for learning
    ActionScript
    >> 3.0, then?
    >
    > The only tough part about making recommendations at this
    point (May,
    > 2007) is that many of the ActionScript 3.0 books are
    still being written.
    > I should clarify that: they're still being written
    specific to Flash (as
    > opposed to Flex). Flex Builder was the first official
    IDE to support AS3,
    > so you'll find Flex books out there, but those may end
    up frustrating you
    > if you're more a Flash dev at heart.
    >
    > I recommended the Moock book to Rothrock specifically
    because we've
    > been friends (Rothrock and I) for some time, and I
    imagine it will be well
    > suited to his comfort level with ActionScript. Moock is
    a gifted
    > communicator, able to explain programming concepts
    clearly. Even so, his
    > books tend to appeal more to intermediate/advanced
    readers, as Rothrock
    > suggested.
    >
    > The Peters book is great for -- as the title implies --
    making things
    > move. It's an animation-via-programming book, and
    belongs within an arm's
    > reach of anyone interested in game development or
    programmatic visual art.
    >
    > For an all-purpose approach to object-oriented
    programming in general,
    > I've been recommending Object-Oriented Programming for
    Flash 8, by Peter
    > Elst and Todd Yard, for a while now. Of course, that
    relates only to
    > ActionScript 2.0. I really don't know if they have a
    second edition in
    > the works, but if so, I would probably recommend it
    without even reading
    > it, as Elst and Yard are top notch developers, and their
    first edition is
    > great.
    >
    > There's a forthcoming Foundation ActionScript 3.0 with
    Flash CS3 and
    > Flex 2, by Steve Webster and Sean McSharry (should be
    ready in June).
    > I've read a handful of early-draft chapters and can say
    it looks
    > promising. That one is geared toward newcomers.
    >
    >
    > David Stiller
    > Adobe Community Expert
    > Dev blog,
    http://www.quip.net/blog/
    > "Luck is the residue of good design."
    >

  • Image re-use in flex

    Hi,
    I am trying out FlexBuilder 3 and seeing if I can put together a first project.
    The layout is in module format, whereby the main application SWF loads modules as necessary.
    The problem I have is that I am trying to find a tidy way to re-use embedded images.
    So far, I have found the following website :
    http://stackoverflow.com/questions/87557/in-flex-as3-how-do-i-get-a-class-definition-of-an -embedded-asset-with-getdefinit
    However I've tried implementing both methods and cannot get the image to load.
    In my last implementation attempt, I've tried the following.
    (1) A class called SVImages
    package com.test.serviceview
        import flash.display.Bitmap;
        [Bindable]
        public class SVImages
            [Embed(source="assets/images/1938022_small.jpg")] private static var WelcomeImage:Class;
            private var _image:Bitmap;
            public function SVImages(name:String)
                //_image = new this[name]() as Bitmap;
                var classDef:Class = SVImages[name] as Class;
                _image = new classDef() as Bitmap;   
    (2) Within one of my modules
        <mx:Script>
            <![CDATA[
                import com.test.serviceview.SVImages;
                [Bindable]
                public var Handshake:SVImages = new SVImages("WelcomeImage");
            ]]>
        </mx:Script>
    <mx:Image id="welcomeimg" source="{ WelcomeImage}" height="174" width="231" y="-2" horizontalCenter="-115.5"/>
    All this compiles fine and there are no problems notified in Flex Builder.  The text label elements of my module show up fine in the application, but the image just does not appear.  I have tried changing the image source to reflect both the relative directory compared to the main application, and the relative directory compared to the module.  Neither option worked.  The image definitley exists because I can browse to it.
    The problem is, I am both a Flex newbie and an ActionScript newbie.... so I don't know where to start looking for what's wrong !
    Thanks for your help

    Before anyone comments,
    public var Handshake:SVImages = new
    is actually
    public var WelcomeImage:SVImages = new
    I'm not that silly

  • Using variable to create a "cartoon strip"

    Ok, here's my situation. It's a bit complicated to explain,
    but probably does not have a complicated answer, so please bear
    with me.
    I'm developing a script that will allow the user (who happen
    to be 2nd grade students) to create their own cartoon strips. This
    is how I'd like it to function:
    The user sees a screen with four images that have some sort
    of visual relationship with each other. The student can arrange
    these pictures by dragging them into a zone of rectangles numbered
    1, 2, and so on. This will determine the sequence the pictures will
    appear in for the next part of the activity. The student then hits
    an "OK" button that will move the user forward.
    Depending on which of the images they chose to be #1, the
    user will see a screen with just that image appearing. To the side
    they will have some cartoon "speech balloons", which will be their
    own dragable movie clips that can be placed on top of the images.
    These speech bubble movie clips will have an area inside them that
    will allow the user to enter text. After the user has positioned
    the speech bubble where they want, and have entered their text into
    the bubble, they hit the OK button to move forward. This process
    will repeat itself for the 2nd imaged, the 3rd, and so on.
    After the student has finished this process with the four
    images and speech balloons, they will be presented with a screen
    which displays all four of the images in the sequence they
    selected, with the speech balloons positioned where they had been
    placed earlier, containing the text they had entered during the
    previous steps. The student will then hit a print button to show
    their work.
    I had first looked into whether Flash was able to do "screen
    grabs" to be saved as .jpgs, but found out this could not be done
    without 3rd party add-on software which I'm unwilling to purchase
    at this point. So the other solution seems to me that certain
    variables need to be saved and retrieved for later.
    The variables would be, the names of the images which had
    initially been selected randomly, the order which the students
    selected them to appear, the ._x and ._y values of the speech
    balloons, and finally the text that was contained within them. I
    know this can be done, but I'm an ActionScript newbie and am not
    sure how to write this in a way that it will work.
    I'm already familiar with how to randomly fetch an image (or
    series of images), and I'm also familiar with how to load Movie
    Clips onto the stage, and I also know how to create the dragable
    movie clips. It's the storing and passing of the variables that I'm
    going to need some help with. Any brave volunteers willing to offer
    me some starting advice? Would it be more helpful if I first had an
    .fla file with the basic elements in place? Please advise, any
    information will be very helpful to me!
    Thank you.

    Hi TylerSong55,
    Thank you for posting in MSDN forum.
    I think the pvdg42's suggestion is right, so we will move this case to this C++ forum, you will get better support.
    Best Regards,
    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click
    HERE to participate the survey.

  • Tween in custom class

    I'm a relative flash/actionscript newbie. I created a towers
    of hanoi solution moving movie clips around using Tweens. This all
    worked great when the action script containing the Tween creation
    existed on what I guess is the root movie clip (within the Action
    script window of my .fla file).
    I tried moving the hanoi solution into a custom class
    (extending EventDispatcher) and now the tween does not 'run'. I've
    stepped through my code with the debugger and added plenty of trace
    statements and am pretty sure all the arguments to the Tween
    constructor are correct.
    _currentTween = new Tween(_movingDiskMc, "_y",
    Regular.easeOut, _movingDiskMc._y, _yMin, _duration);
    Is there something fundamental I'm missing? Is the frame rate
    an issue with the custom class? The value of _duration above is 5.
    thx
    - Kurt

    ahhhh.... after further review found that my
    'onMotionFinished' event handlers were being called but in the
    debugger the scope is the Tween class not my Hanoi class. That's
    messed up
    found the discussion in the help topic regarding scope of
    event handlers and using the 'suggested strategy' things are
    working fine now

  • Can't get 1st node in XML to display

    I am an ActionScript newbie and so I found a tutorial on
    kirupa.com for a xml slide show that I was able to adapt to create
    a scoreboard for football scores. Most of it seems to work just
    fine. When I click the next and previous buttons, the scores cycle
    through but when I initially launch, the first score doesn't
    display. The tutorial had an image loader to make sure the files
    had completely loaded and I had no need for it so I removed that
    part but evidently what I removed also helped to display the first
    node. Any help would be awesome!

    Thanks dude! Sometimes all it takes is a second set of eyes
    :-)

  • Unable to Remove Movie Clip

    Hello... I am an ActionScript newbie. I followed a tutorial
    from computer arts magazine, to create a portfolio using
    actionscript and xml. I linked the portfolio to several scenes in
    flash, such as contents and contact details. My problem is that
    when I placed a button "back" on the main stage of the portfolio,
    to redirect to the contents page, the list of artworks thats
    populated from xml remains on the next scene, or any other scene i
    link it to. I tried using unload movie clip, but nothing is
    working. Please Help. This is my actionscript:
    I don't if this helps, but I get this message in the output
    panel: Target not found: Target="_root.btn_projectsundefined"
    Base="_level0"

    check the flash help files. there's no better way to debug
    your flash applications than the liberal use of the trace()
    function.
    for example:

  • Flash profile for iRiver e100

    Does anyone know the parameters to create a template/profile
    for the iRiver e100? I'm looking at creating some educational games
    for my classroom to be played on these iRivers that we have. I'm
    told the resolution is 320x240, but I don't know the size? Do I
    keep the frame rate at 15?
    Thanks in advance (Flash, actionscript newbie)

    Does anyone know the parameters to create a template/profile
    for the iRiver e100? I'm looking at creating some educational games
    for my classroom to be played on these iRivers that we have. I'm
    told the resolution is 320x240, but I don't know the size? Do I
    keep the frame rate at 15?
    Thanks in advance (Flash, actionscript newbie)

  • Newbie questions on fms and actionscript 3

    Ok, like I said I'm a newbie, but I do understand the differance between ssas and as3. Not all, but all most everything I see written in SSAS can be writen into a external AS3 file. This leads me to quite a few questions I'm hoping you kind people can shed some light on for me.
    1)  What is the advantage of writing a SSAS file over an external AS3 file?
    2) Can I write an .asc file in AS3 or do I have to use AS1? Please understand I'm using tuts from fmsguru.com and the books "Learning Flash Media Server" (pdf) and "Programming Flash Communication Server". I'm not a javascript programmer so nothing I do in AS1 seems to make any sence while everything I do in AS3 does. It may not seem like it to you people that are programmers, but to those of us that aren't, AS1 and AS3 are miles apart.
    3) kind of off topic, but a security question. I'm not a "hacker" and don't like the jerks that are. My question is on external AS / SSAS files and swf files. When my fla is compiled into a swf does my external AS files remain external? I assume they do, but then what is the threat of the swf being decompiled? In most projects I would do I could care less if somebody had access to my fla as long as they don't have my actionscript files.
    I don't know. Maybe on questions one and two I'm getting confused becasue I'm using out dated material. Again I assume that even though fms was built off of the javascript engine it should be able to read and execute my AS3 file. Other wise what was the point of the evolution of actionscript into a fully functional programming language?
    Thanks for any help you might have...

    1) I did not get this question correcly - for that matter SSAS can only be in AS1 - so i dont see reason comparing them
    2) It has to be AS1
    3) if you doing "include" stuff - i think code would go into compiled swf and proper decompiler would give you the code.
    Last para - Server-side engine understands only AS1 so it wont be able to read and understand your AS3 file.

  • Newbie having difficulty centering images in browser using ActionScript 3.0

    I'm a newbie using flex builder 3. I'm learning
    ActionScript3.0. After running the AS code from the book, my images
    are never in the center of the browser(IE7). After running the
    following code (which is supposed to produce a yellow arrow, in the
    center of the stage, that rotates to the mouse), I get all the
    desired results except the arrow is positioned in the bottom right
    corner of my browser and only part of the arrow is visible. if
    anyone can suggest a solution it would be highly appreciated.
    Please keep in mind that I am a COMPLETE newbie to ActionScript,
    Flex Builder 3, and the Flash environments. Thanks in advance.

    on mouseup or click, if the mouse is down, you can use:
    stage.focus=outputText;
    if the mouse isn't down, you can don't need a listener to trigger the above.

  • Newbie Q: What do movie clips need to allow Actionscript?

    Hello. Thanks for taking time out for this question.
    Basically, I started an exercise in a book and it asked me to
    add code to a movieclip. I created a basic circle, converted it to
    a movie clip and tried to press F9 for actionscript, but Flash told
    me "Current selection cannot have actions added to it".
    When I looked at the example file that came with the book, I
    couldn't see anything special about the movieclip that was used.
    What am I missing?

    However, the techniques of adding code directly to movie
    clips is an old and outdated way of coding. And I would advise that
    if you are serious about learning Actionscript that you don't go
    down that road.
    AS 2 is perfectly useful and good so learn that or learn AS3
    (or both!), but here is a link to an article about the issue:
    http://www.quip.net/blog/2006/flash/museum-pieces-on-and-onclipevent
    David Stiller (that is his blog) posts here often and is a
    great source of information. You might want to check out more of
    his articles.
    It could be that your book is just showing one way before
    moving on to a more sensible approach, but check the examples
    toward the end. If they are full of on() and onClipEvent() I woudl
    recommend getting a different book.

  • Newbie - how to change the color of a line using ActionScript?

    This must be the most basic question in the world, but I've
    been searching the documentation for an hour.
    All I want to do is to draw a line on the stage, and then
    change its color (or endpoint positions) dynamically using
    ActionScript.
    This is the 1st step to creating complicated dynamic
    animations... (No, I do not want to use the timeline, I want to do
    it dynamically.)
    Yet a line can't be an instance, so I'm confused -- how can I
    possibly do this? Is there some key concept I'm missing here?
    Thanks
    Michael

    AS2 required you to create your own function for doing
    primitive shapes. In AS3 that has changed and the graphics package
    includes not only the old AS2 drawing API but also has methods for
    doing squares, circles etc.
    If you are a VB programmer, my honest opinion is to leave
    your traditional OOP mindset at the door when using Flash.
    Actionscript is still in its infancy and although AS3 does really
    strive for OOP oneness, it isn't there 100% like VB is which has
    been around 20 years longer and gone through numerous additions
    etc. Whenever I learn a new language VB, PHP, C, AS, Java....I try
    my best to look at the language as its own identity. All language
    share similarities but they all have their own idiosyncrisies. Keep
    an open mind and you'll find what you need.
    Most of the seasoned guys here will also tell you that
    although the documentation is decent, you are better off going out
    and picking up a book on Flash 8/CS3 and another one on
    Actionscript. Familiarize yourself with the program that way.
    With your programming background, I'd recommend picking up
    Essential AS2 (or AS3) by Moock depending on your version of Flash.
    Also, if you are more interested in the programmatic side of Flash,
    why not look into Flex Builder and AIR. Since it is purely a
    programming environment (no Flash IDE), you'd be more
    comfortable.

  • Playing sound using ActionScript 3.0 (newbie)

    I have a Flash animation I've created, and at the last minute we have decided to add one audio track to the background.  The problem is, I have a looping animation in the timeline, so simply inserting the audio into a layer in the timeline will not work (because it will loop as well).
    Can anyone help me with how to insert just one sound file "on top" of all the animations playing using ActionScript 3.0?  I've never worked with the Sound class, and have never put audio into a Flash file besides simply importing it into a frame.
    THANKS!
    Jen

    Worked perfectly.  Thank you thank you!
    Jen

  • Newbie: binding actionscript var to textinput

    Hi,
    I'm just starting with flex, and have a simple question on
    bindings. I've created the following application (using flex3 beta
    3, and flexbuilder):
    <?xml version="1.0" encoding="utf-8"?>
    <mx:Application xmlns:mx="
    http://www.adobe.com/2006/mxml"
    layout="absolute">
    <mx:Script>
    <![CDATA[
    [Bindable]
    public var customerName:String = "customerName";
    ]]>
    </mx:Script>
    <mx:TextInput text="{customerName}" x="187" y="92"/>
    <mx:Text text="{customerName}" x="368" y="94"/>
    <mx:Button click="customerName += 'z'" x="473" y="92"
    label="add z"/>
    </mx:Application>
    The problem: the variable customerName isn't changed when i
    enter some text in the textinput. Pressing the button does the
    expected thing: changes the variable, which is displayed correctly
    by the textinput and text components.
    My goal is to create a datamodel using an actionscript
    object. I've seen some examples where the datamodel is bound to the
    textinput (the other way around), but it seems to me that it would
    be better not to tie a datamodel to one single input component. I
    may want to modify the data using multiple components.
    Thanks,
    Andrej

    My 2 cents: There is often a misconception that when making a
    variable bindable, it is a two-way binding, in other words, the
    entity that is bound to the variable will be updated automatically
    AND the variable will be updated if the entity's value changes (a
    circular binding).
    Making your variable [Bindable] means that there is a single
    observer, like your TextInput, of a variable, like customerName. If
    the customerName variable changes, then the TI will change, not the
    other way around.
    Your approach of using the Binding tag with a reciprocal
    source and destination should be fine.
    My approach usually is to set the initial value I want
    displayed in the TI from elsewhere. Then the TI is strictly used as
    the control to input data in order to update a variable on the
    'change' event. I often bind to a function that'll automatically
    perform XYZ for me on a specific event.
    TS

  • Newbie is still being stupid! Actionscript for a button to a URL isn't linking??

    Not sure what I am doing wrong now.  I have coded the frame as below, yet when I publish it it doesn't link?  Any suggestions? (obviously a false link here, but am using a link that actually works!)
    stop();
    var getPaypalBoostaboiler:URLRequest = new URLRequest("http://www.addressgoeshere.co.uk");
    //---Get URL---\\
    paypal_boostaboiler.addEventListener(MouseEvent.CLICK,boostaboilerBuy);
    function boostaboilerBuy(event:MouseEvent):void{
    navigateToURL(getPaypalBoostaboiler);

    Just uploaded it and it works fine now - I HAVE SO MUCH TO LEARN!!!
    Thank you so much for your help.

Maybe you are looking for

  • MB990 and SL - Fan speed is not increasing automatically

    Hi Guys, Two days ago I changed my macbook's hard drive to a bigger one and did a fresh install of Snow Leopard. As soon as I installed the SL I noticed my computer was running hotter than the previous installation. Without doing anything, my macbook

  • Corruption of data

    Something very strange is happening in our environment - when I run a query logged in as Administrator on my PC (Windows 2000), everything is fine. When I am logged in as myself (with admin rights), the data returned is corrupted and displays junk. W

  • How to install downloaded app on to iPhone

    How do I install a downloaded app onto the iPhone?

  • After v1.90 BIOS update Satellite Pro A300-1EA wont boot up

    I have just upgraded my laptop to the new BIOS as stated in the title but after doing it my computer now wont boot up at all. I just get a blue screen with it asking me to do a CHKDSK because there might be a virus or that the hard drive isn't connec

  • Multiple contact sheet from multiple image folders

    Hi everybody, I have a folder with 120 subfoders with 30 images each,  is there a "automatic way" to make a  contact sheet of every subfolder: 120 contact sheet of 30 images in this case?  i need help