Actionscript 2 Troubles

Hi there,
If anyone has some advice, it would be greatly appreciated. My client bought a flash file that turned out to be a bit of a surprise and has lead to hours of fruitless testing to get the file to work.
The file she purchased is here.
http://flashden.net/item/animated-cubes-mouse-illumination-as2/44429
I managed to tweak the file to do what the client had asked for, but upon trying to use the file and make it link from Scene 1 to Scene 2, I have had nothing but errors.
The code is below. Is it possible to add a link to this? The cursor has a roll-over feature that is at odds with the button behavior that I am trying to add.
Any advice would be greatly appreciated. Thanks everyone.
//hide InfoText from Animation
InfoText._visible = false;
//set cube width and height
CubeWidth = 14;
CubeHeight = 14;
//set stage width and height
StageWidth = 600;
StageHeight = 343;
//create cubes to fill screen verticaly and horisontaly
for (i = 0; i < (StageWidth / (CubeWidth + 1)); i++){
    for (j = 0; j < (StageHeight / (CubeHeight + 1)); j++){
        t = attachMovie("CubeAnimation", "Cube" + i, this.getNextHighestDepth());
        t._x = (CubeWidth + 1) * i;
        t._y = (CubeHeight + 1) * j;
        t._width = CubeWidth;
        t._height = CubeHeight;
        t.onRollOver = OverCube;
        t.onRollOut = OutCube;
        t.MinimumAlpha = t._alpha = 30 + Math.random()*20;
        t.GoingBrighter = Math.round(Math.random()*1);
        t.onEnterFrame = CubeEnterFrame;
        t.useHandCursor = false;
//iluminates cube when mouse over it
function  OverCube() {this.gotoAndPlay(2);}
//deluminates cube when mouse over it
function OutCube() {this.gotoAndPlay(7);}
//illuminate and deluminate cubes on every frame
function CubeEnterFrame() {
    if (this.GoingBrighter == 1){this._alpha = this._alpha + 0.5;}
    if (this.GoingBrighter == 0){this._alpha = this._alpha - 0.5;}
    if (this._alpha <= 30){this.GoingBrighter = 1;}
    if (this._alpha >= 50){this.GoingBrighter = 0;}

I actually have tried tweaking the file a little, and imported my 
frames inside the movie clip, and made an action on clip that advances 
the frame as desired. It works without error with the exception that 
the scripted cubes remain on the stage. You can view here:
http://www.robindavies.ca/animatedcubes_A_orangeClipNu.html
Is it possible to make a function that would make my symbols ( "Cube" 
graphic and "CubeAnimation" movie clip ) go to an alpha of 0% on 
release?
The cubes are already scripted to change in appearance so it would 
seem this is possible.
I know that this solution to the problem is more than likely less than 
ideal from a best practices standpoint, but at least it is a solution.
I have tried to make additional functions below to the code without 
success.
Thanks for any helpful ideas.
//hide InfoText from Animation
InfoText._visible = false;
//set cube width and height
CubeWidth = 14;
CubeHeight = 14;
//set stage width and height
StageWidth = 600;
StageHeight = 343;
//create cubes to fill screen verticaly and horisontaly
for (i = 0; i < (StageWidth / (CubeWidth + 1)); i++){
     for (j = 0; j < (StageHeight / (CubeHeight + 1)); j++){
          t = attachMovie("CubeAnimation", "Cube" + i, 
this.getNextHighestDepth());
          t._x = (CubeWidth + 1) * i;
          t._y = (CubeHeight + 1) * j;
          t._width = CubeWidth;
          t._height = CubeHeight;
          t.onRollOver = OverCube;
          t.onRollOut = OutCube;
          t.onRelease = ClickCube;
          t.MinimumAlpha = t._alpha = 30 + Math.random()*20;
          t.GoingBrighter = Math.round(Math.random()*1);
          t.onEnterFrame = CubeEnterFrame;
          t.useHandCursor = false;
//iluminates cube when mouse over it
function  OverCube() {this.gotoAndPlay(2);}
//deluminates cube when mouse over it
function OutCube() {this.gotoAndPlay(7);}
function ClickCube() {gotoAndPlay("Frame2");}
//illuminate and deluminate cubes on every frame
function CubeEnterFrame() {
     if (this.GoingBrighter == 1){this._alpha = this._alpha + 0.5;}
     if (this.GoingBrighter == 0){this._alpha = this._alpha - 0.5;}
     if (this._alpha <= 30){this.GoingBrighter = 1;}
     if (this._alpha >= 50){this.GoingBrighter = 0;}

Similar Messages

  • Basic Actionscript Trouble in CS3

    In MX, and in Flash 8 I had no problems with making buttons
    and putting some basic actionscipt on it. In CS3 for some reason
    when I make a button, look in the properties window and the button
    windows there (which tells me I'm on the buttons layer) but when I
    go to put the actionscipt in, it doesnt allow it. It says "Cannot
    add actionscript because blah blah". It only allows it with the
    frame, not the button if that makes any sence. Why is this?

    Ok, will try. However I tried that one I think. I changed it
    to AS2 (not from the beginning). So basiclly open a new Flash FLA
    and how do I make it ONLY go to AS2? Thanks

  • New to flash actionscript, making a game.

    Hi. My name's Rory.
    I am an artist.
    http://www.youtube.com/profile?user=PimpOfPixels
    http://roaring23.cgsociety.org/gallery/
    I am learning action script and Flash so that I can make
    games.
    I am not a complete novice in programming. I am proficient in
    Java and in MaxScript (3DSMAX embedded language).
    I have been making some progress in action script and I have
    a functional (although incomplete) game in the works. You can view
    it here:
    http://secure2.streamhoster.com/~rlu...orniverous.swf
    The idea is it's a color game
    red beats green, green beats, blue beats red. Think paper
    scissor rock.
    The idea is to change the entire circle into one color.
    The graphics are place holders BTW.
    I am using FlexBuilder 2.0 and Flash CS3, and I have come
    across a problem not covered in either of my books.
    I'd really appreciate any help that you guys can offer.
    I have gotten this far on my own.
    My #1 question (and I have many more) is:
    How do you through Flash specify animation segments for a
    MovieClip Symbol?
    Notice how the red creatures occasionally open their mouths.
    I want to have a walk, an attack, an absorb, and a bounce animation
    on the same timeline and trigger the appropriate one depending on
    which color the creature collides with. I do not know how to go
    about this problem. I’ve just been trying to get the walk
    animation to loop without playing the attack animation so far.
    I've tried frame-labeling in flash, with scripts on the key
    frames of a second layer that specify when to stop or repeat the
    animation... No dice.
    I have a symbol named RedShot in the library of a flash
    project named "graphics"
    In my timeline I have 2 animation segments, and I have a
    second layer denoting two corresponding frames named "walk" and
    "attack" from the properties menu.
    On the final frames of the animations I have scripts.
    Code:
    gotoAndPlay("walk");
    and
    Code:
    gotoAndPlay("attack");
    respectively.
    Im my library I have linkage options specified as such:
    Class:RedShot
    BaseClass:flash.display.MovieClip
    export of actionscript#CHECKED
    export on 1st frame#CHECKED
    on the main stage of my flash project I have actionscript for
    2 functions:
    Code:
    function walk(){
    red_shot.gotoAndPlay("walk");
    function attack(){
    red_shot.gotoAndPlay("attack");
    I export the project and the opened window has the "walk"
    animation looping properly.
    In my FlexBuilder project I embed the symbol
    Code:
    //Inside class global variables:
    [Embed(source="../graphics.swf", symbol="RedShot")]
    public var RedShot:Class;
    private var _shot:MovieClip;
    Code:
    //and in my buildShot function:
    _shot = new RedShot();
    addChild(_shot);
    When I build the project the characters appear, and they
    animate. The only trouble is that there are no breaks in the
    animation. The animation loops right through the frames where I
    have specified that the animation should "gotoAndPlay" from a
    different part.
    What's weirder is that I can call
    Code:
    "gotoAndPlay("attack");"
    without an error and it will go to and play from that point.
    The only trouble is that it will begin to loop the entire animation
    again without stopping at the gotoAndPlay events stored in the
    frames of the timeline.
    It seems like all embedded actions are ignored, add I can't
    think of another way to controll the animation.
    Any thoughts?

    After hours of searching the internet I finally got this
    blasted question figured out.
    How to you export a symbol from Flash for use in a Flex
    Builder project without destroying actionscript stored within the
    frames of the Symbol's timeline?
    That's a long winded way of saying: "In FlexBuilder, how do
    you control MovieClips from Flash". I'm trying to make games, and
    this was a particularly important question for me :).
    Here's how:
    1) You need a hotfix from Adobe.
    [HTML]http://kb.adobe.com/selfservice/viewContent.do?externalId=kb401493&sliceId=2[/HTML]
    This allows Flash CS3 to export a SWC file.
    2)You have to set the linkage properties for your various
    symbols in the flash library panel.
    a)right click on symbol in library panel
    b)choose "linkage"
    c)"Class:" = (pick a name)
    d)"Base class:" = flash.display.MovieClip;
    e)"Export for ActionScript" = CHECKED
    f)"Export in first frame"=CEHCKED
    3)If you want to have multiple segmented animations as I
    certainly did you'll want to create frames and actionscripts within
    the symbols timeline to define where these animations are.
    a) in the symbol's timeline make a second layer. We'll name
    that layer "labels" for the sake of not having this get too
    confusing.
    b) on that layer create a new frame for each of the animation
    segments that you'd like to define and stretch them to the length
    of the corresponding animations.(I'm assuming that you have a
    keyframe animation on the 1st layer... otherwise what's the point
    of all this :P?)
    c)in the properties panel name the frames in the "labels"
    layer accordingly ie. "walk" "run" shoot" etc.
    d)Define whether the various animations play once or loop by
    adding a script to the last frame of the animation. If you want the
    animation to loop add
    [CODE]gotoAndPlay("name-of-the-animation");[/CODE]
    if you want the animation to play once and stop add
    [CODE]stop();[/CODE]
    if you want the animation to play once and then return to a
    different animation add
    [CODE]gotoAndPlay("name-of-a-different-animation");[/CODE]
    4) now you can export the symbols to an SWC file. Note: you
    do not get this option unless you have installed the hotfix.
    [HTML]http://kb.adobe.com/selfservice/viewContent.do?externalId=kb401493&sliceId=2[/HTML] .
    a)rightclick on a symbol in the library panel
    b)choose "exportSWCfile..."
    c)export the file to a logical place such as the root of your
    FlexBuilder project.
    5) Now you have to tell flexbuilder about the new SWC file.
    Note: Once this file is added to the FlexBuilder library you can
    instantiate classes from it as though they were included using the
    "include" function.
    a)Right clicking on the root of the project in the Navigator
    view.
    b)going to properties.
    c)Going to library path. (2nd tab)
    d)and pressing the "Add SWC" button
    Now you're done and you can instantiate any of the symbols
    from your library while preserving any actions from your symbols
    timeline just as though you had imported it as a class from a
    typical library.
    Sweet huh?
    Thanks to the countless people and internet resources I found
    on the subject. Hopefully it will be easier for anyone who finds
    this post.
    Here's an adobe video which covers the basic process.
    https://admin.adobe.acrobat.com/_a300965365/p75214263/

  • In actionscript 3.0 how do i make a nested movie clip button go to a frame on the main timeline

    I am making a website based in flash actionscript 3.0 i have a button nested in its own movie clip, because I have the button expanding to be able to read it i have figured out the only way to do this is by creating it as a movie clipa nd inside the movie clip creating it as a button
    I added an event listener to the blog button by saying,
    blog.addEventListener(MouseEvent.ROLL_OVER,gotoblog);
    function gotoblog(evtobj:MouseEvent){
         gotoAndStop(2)
    this part of the code works it goes to the 2nd frame of the timeline it is in and stops wich is a blown up version of the origanal symbol
    i added on frame 2 a second command
    blog.addEventListener(MouseEvent.CLICK.gotoblogpage);
    function gotoblogpage(evtobj:MouseEvent){
    gotoAndStop("blogframe")
    trace("the blog button was clicked")
    i have named the symbol blog and have name the frame of where the blog page is going to be "blogframe" this line of code at the bottom is where i run into trouble the output window in Flash is saying "The blog button was clicked" just like i want it to. no errors are accouring why than is the playhead not going to frame "blogframe"? if the button is working when i click it the code is right i belive the problem here is it does not want the playhead to go to the frame i want it to. So i gues my question is, how can i make a button withing a movie clip interact with the main timeline?

    I have a similar problem if could please help me i'd really apreciate it!!
    So i have a looping animation of some thumbnails, the hierarchy goes like this
    Scene1(main timeline) -> imgBar(MC)->imgBarB(MC within the imgBar MC)
    My buttons symbols are in the last MC "imgBarB" where i have this code:
    ss1.addEventListener(MouseEvent.CLICK, OneButtonClicked);
      function OneButtonClicked(event:MouseEvent):void{
      MovieClip(root).gotoAndStop("ssbox1");
    I want to control the Btns in my "imgBarB" MC to play a labeled frame(named "ssbox1") on another MC on the main timeline,this other MC goes like this:
    Scene1(main timeline)->ssbox_mc(MC where my labeled frame is)

  • How to get/set value in illustrator preference file using ActionScript 3.0

    Hi all,
    I want to get/set the flex panel components preference in illustrator preference file using ActionScript 3.0.
    I tried to achieve this  like --
    import com.adobe.illustrator.Preferences;
    var pref : Prefereneces = new Preferences();
    //To set value I used  this...
    pref.setStringPreference("url", id1.text);
    //To get value I used this..
    id1.text = pref.getStringPreference("url");
    i think there is prb in creating  Preference variable but I am unable to resolve.
    plz help.
    Thanks.

    I am having trouble with setStringPreference. It seems to be setting the value to 0 in the Prefs file. When I first wrote the code, it was working, but something is keeping it from saving the right value now. Did you get yours working? Any ideas?

  • Unable to map actionscripting with java nested objects

    Hi Experts...,
    Im a newbie in flex and actionscripting.....
    Im unable to map nested java classes and objects with my front end flex application using actionscript....I have searched everywhere almost to my knowledge on the net but failed to find a fix...,
    im having serious trouble reffereing to attributes of an object using another object( which by the way happens to be the parent object).
    Im using hibernate and springs to do the DB transactions....,
    Please help me out with this issue.....
    Thanks for all the help and support in advance....

    Again, I don't work with Java and you should ask Java-related question in Flex (or Java) forum.
    Java or not - you need to package your server side language specific object into something that AS understands (text, XML, AMF object) and load this data into AS via, perhaps, URLLoader. Or you can open socket. Then you parse this data with AS3 code in SWF.

  • I am trying to experiment with Tweens and Easing Types in ActionScript 3.0, Adobe Flash CS4. help

    I am using ActionScript 3.0, Adobe Flash CS4 software
    I have created Tweens for some MovieClip properties and experimented with some of the easing types.
    This is what I have managed to create and works okay!
    grow_btn.addEventListener(MouseEvent.CLICK, grow);
    shrink_btn.addEventListener(MouseEvent.CLICK, shrink);
    rotate_btn.addEventListener(MouseEvent.CLICK, rotate);
    hide_btn.addEventListener(MouseEvent.CLICK, hideClip);
    show_btn.addEventListener(MouseEvent.CLICK, showClip);
    fadeOut_btn.addEventListener(MouseEvent.CLICK, fadeOut);
    fadeIn_btn.addEventListener(MouseEvent.CLICK,fadeIn);
    function grow(e:MouseEvent):void {
                    var scale1:Tween = new Tween(instrument, "scaleX", Back.easeIn, 0, 1, 3, true);
                    var scale2:Tween = new Tween(instrument, "scaleY", Back.easeIn, 0, 1, 3, true);
    function shrink(e:MouseEvent):void {
    var oneSmall:Tween = new Tween(instrument, "scaleX", Back.easeInOut, 0, -.2, 3, true);
    var twoSmall: Tween = new Tween(instrument, "scaleY", Back.easeInOut, 0, -.2, 3, true);
    function rotate(e:MouseEvent):void {
    var spin:Tween = new Tween(instrument, "rotation", Elastic.easeOut, 0, 360, 5, true)
    function hideClip(e:MouseEvent):void {
    instrument.visible = false;
    function showClip(e:MouseEvent):void {
    instrument.visible = true;
    function fadeOut(e:MouseEvent):void {
    var tweenfadeOut:Tween = new Tween(instrument, "alpha", None.easeOut, 1, -.1, 3, true);
    function fadeIn(e:MouseEvent):void {
    var tweenfadeIn:Tween = new Tween(instrument, "alpha", None.easeIn, 0, 1, 3, true);
    I am having trouble creating Tweens and add easing types for the action script below!
    I keep getting error message (“Access of undefined property Sine”) for example when I type
    function hideClip(e:MouseEvent):void {
    var noClip:Tween = new Tween(instrument, "visible", Sine.easeOut, 0, 1, 3, true);
    Can anyone help???? The original script is below
    hide_btn.addEventListener(MouseEvent.CLICK, hideClip);
    show_btn.addEventListener(MouseEvent.CLICK, showClip);
    function hideClip(e:MouseEvent):void {
    instrument.visible = false;
    function showClip(e:MouseEvent):void {
    instrument.visible = true;

    make sure you have imported the Sine class
    import fl.motion.Sine;

  • Trouble passing var using CFC

    I'm having trouble passing a variable value called from a CFC
    into Flex via RemoteObject. Basically I'm trying to pass the
    current logged-in user to a Combobox as a string. The Web directory
    in IIS is set to dissallow anonymous access and is set to
    Integrated Windows Authentication. The CFC is in the secured
    directory as well as the Flex app. If I change the CGI variable to
    something like #cgi.remote_addr# among others it works fine so I
    know it's not the actionScript or CFC code. Any ideas as to why
    #cgi.auth_user# is passing as an empty string?? One more caveat. If
    I invoke the function in my CFC from a .cfm page the auth_user is
    displayed as expected.
    ------------------------------------------------------------------------------------------ ----------

    To use RemoteObject with PHP you need to download AMFPHP and
    make some settings.
    To download go here:
    null.
    To understand how to use it with Flex go here:
    null.
    This is a video tutorial of about 7-10 minutes which will show you
    all you need you need to know to set AMFPHP in 'conversation' with
    Flex.
    Good luck!

  • Actionscript 3.0 - Button to open URL

    I'm attempting to have a basic FlashCS4 intro/splash screen for my  website, that after finished playing is a button that links to the  first page of my site.
    I have the animation created, I'm just having trouble actually  linking it to the page.
    When I test the movie, I get the error:
    TypeError: Error #1009: Cannot access a property or method of a null  object reference.
    at splash_fla::MainTimeline/frame66()
    Frame 66 being the frame with the button and actionscript on it:
    enter_btn.addEventListener(MouseEvent.CLICK,goThere);
    function  goThere(e:MouseEvent) {
    var request:URLRequest=new  URLRequest("*******");
    navigateToURL(request);
    I'm very much an AS3 beginner, so it may just be a simple fix, but  I'm at a loss. Any help would be greatly appreciated!

    If that is the only code you have, chances are your enter_btn is not named or is otherwise out of scope.  Instance names are assigned by selecting the object on the stage and assigning the name in the properties panel where it says instance name.  If you did that okay, then maybe the problem is that the code is executing where the button doesn't exist-- they need to be in the same frame (Not layer, just frame).
    The 1009 error indicates that one of the objects being targeted by your code is out of scope.  This could mean that the object....
    - is not in the display list
    - doesn't have an instance name (or the instance name is mispelled)
    - does not exist in the frame where that code is trying to talk to it
    - is animated into place but is not assigned instance names in every keyframe for it
    - is one of two or more consecutive keyframes of the same objects with different names assigned.
    If you go into your Publish Settings Flash section and select the option to Permit debugging, your error message should have a line number following the frame number which will help you isolate which object is involved.

  • Trouble with a simple transition

    I'm new to actionscript and trying to wrap my head around some simple scripting, but am having trouble.
    My goal in this excercise is to have one symbol/movie clip in frame 1 (stopped on that frame) and then, when clicked, the first cube will dissapear and transition to a different symbol/movie clip in frame 2.
    Here is my script:
    stop();
    stationary1.addEventListener(MouseEvent.CLICK, transition);
    function transition(evt:MouseEvent):void {
        evt.currentTarget.gotoAndStop(2);
        evt.currentTarget.mouseEnabled = false;
    The movie clips I'm working with are just revolving cubes that are different colors. What happens when I run this script is the initial cube is there spinning as intended in frame 1, then when I click it the initial cube freezes and the other cube doesn't show up.

    you probably don't want the evt.currentTarget to advance to frame 2.  that would be the 2nd frame on stationary1's timeline.
    try:
    stop();
    stationary1.addEventListener(MouseEvent.CLICK, transition);
    function transition(evt:MouseEvent):void {
    gotoAndStop(2);

  • 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

  • Code to do a completely external actionscript 3 file?

    If it's not too much trouble, could somebody post an actionscript .as file that would draw a rectangle on the flash stage, with the ONLY thing in Flash being the property assignment that you have to do.
    I'm really new to this, and I have not been able to find any tutorials on this topic (other than someone telling me that the tutorials are out there).  I want to start hacking around with Actionscript and Flash, but I'm really frustrated because I can't get started.
    I DON"T want to put code in the timeline, use code snippets, or use the actions window.
    References to specific tutorials would be really appreciated.
    Thanks!

    Here is a class that draws rectangle:
    package
         import flash.display.Graphics;
         import flash.display.Shape;
         import flash.display.Sprite;
         import flash.events.Event;
         public class ObjectWithRectangle extends Sprite
              public var fillColor:uint = 0xff0000;
              public var strokeColor:uint = 0x00ff00;
              public var rWidth:Number = 100;
              public var rHeight:Number = 100;
              public function ObjectWithRectangle()
                   if (stage) init();
                   else addEventListener(Event.ADDED_TO_STAGE, init);
              private function init(e:Event = null):void
                   removeEventListener(Event.ADDED_TO_STAGE, init);
                   var rectangle:Shape = new Shape();
                   var g:Graphics = rectangle.graphics;
                   g.lineStyle(1, strokeColor);
                   g.beginFill(fillColor);
                   g.drawRect(0, 0, rWidth, rHeight);
                   g.endFill();
                   addChild(rectangle);
    Here is a class that implements the above class - if you make it a document class is Flash IDE - it will show a rectangle with random colors:
    package
         import flash.display.Sprite;
         import flash.events.Event;
         public class DocClass extends Sprite
              public function DocClass()
                   if (stage) init();
                   else addEventListener(Event.ADDED_TO_STAGE, init);
              private function init(e:Event = null):void
                   removeEventListener(Event.ADDED_TO_STAGE, init);
                   var rect:ObjectWithRectangle = new ObjectWithRectangle();
                   rect.fillColor = 0xffffff * Math.random();
                   rect.strokeColor = 0xffffff * Math.random();
                   rect.rWidth = 200;
                   rect.rHeight = 250;
                   addChild(rect);

  • How to put ActionScript into Catalyst project via Flash Builder?

    I don't know if this is the wrong place to put this, but I need to add some ActionScript into my Catalyst project... from what I understand, it can only be done via Flash Builder. Am I right? How?

    Hi Alex,
    To edit the code of a Flash Catalyst project, you can import it into Flash Builder as follows:
    File > Import > Flash Builder Project
    Select the FXP file from Catalyst
    Make sure "Import new copy of project" is selected, then hit Finish
    I'm not sure where you got the ActionScript code that you're planning to use, but it may be difficult to integrate into your project if it's not designed for use with Flex (a lot of AS code snippets you'll find online are just for general use in Flash, not tailored for Flex applications).  But you'll probably want to do something like this:
    Locate the image you want to make random.  If you're having trouble doing this, switch the view to Design mode, select the image with the mouse, and then switch back to Code mode to see the corresponding code highlighted.
    If there's no id attribute set on the image, add one (so you can refer to it in code later).
    If the tag is s:BitmapImage, change it to mx:Image (this is needed to make the contents dynamic)
    If the root s:Application tag doesn't have a creationComplete handler, add one (type it partway, then hit Ctrl+Space, then choose "Generate Handler").
    In the handler, add your code to randomly select an image filename.
    Then set <your image's id>.source = <filename>
    Hope that helps!
    - Peter

  • How do I build a Scroller in Actionscript?

    I need to build a Scroller / Group / RichEditableText set of components using only Actionscript, since I need to create (perhaps) many of these, skinned on-the-fly as a result of download from the server.
    Can anyone provide a working example?  I can see how to do it using MXML, but I'm a programmer at heart...  Only actionscript?  I've tried but I'm having trouble getting the pieces to play together (scroll bars, mouse wheel, etc.)
    Or is there a way to create multiple instances of a set of components defined in MXML?  That might do it too.
    Thanks.
    Oz

    I have a very dynamic application:  the windows and components come and go, and I don't know in advance how many there will be, what the styles will be, etc.
    So I want to create all components with Actionscript classes.
    This is the MXML code that creates what I want.. This works fine, scrolls, mouse-wheel, all controls are effective.
    <s:Scroller id="myScrollerA" width="300" height="100">
        <s:Group id="myGroupA">
            <s:RichEditableText id="myTextA" paddingTop="20">
                <s:textFlow>
                    <s:TextFlow>
                        <s:p fontWeight="bold">This is paragraph 1.</s:p>
                        <s:p>This is paragraph 2.</s:p>
                        <s:p>This is paragraph another.</s:p>
                        ... more code here with more text
                        </s:TextFlow>
                </s:textFlow>
            </s:RichEditableText>
        </s:Group>
    </s:Scroller>  
    This is the Actionscript I'm starting with, but the linking between the vertical scroll bar and the text scrolling is not functioning, and there are various surprises.
                  sxText is an instance of my custom class which subclasses RichEditableText, with more text than will fit into the scroller.
                group = new Group();
                group.addElement(sxText);
                group.setContentSize(sxText.contentWidth,sxText.contentHeight);
                scroller = new Scroller();
                scroller.setStyle("horizontalScrollPolicy","off");
                scroller.setStyle("verticalScrollPolicy","on");   
                scroller.viewport = group;
                scroller.addEventListener(MouseEvent.MOUSE_WHEEL,scrollWheelEvent);
    The scroll bar does scroll the content area, but NOT the text -- the text disappears off the top, but the revealed area at the bottom is background color: no text content.
    Mouse wheel on the text area functions, but the scrolling is not reflected in the scroll bar.
    Also puzzling:  the thumb component of the scroll bar changes to a large vertical size, on first click into any scroll bar component.
    What else do I need to do to tightly couple the scrolling of the text area and the use of the vertical scroll bar?  Am I missing some skinning methods?
    Thanks for your attention.

  • Actionscript help on semi-advance flash

    So I'm trying to create a flat carousel similar to the one
    located here
    http://www.square-enix.com/na/index_f2.html
    (as a side note before reading the 2nd half, my trouble is with
    the thumbnail loop buttons)
    I have created all the graphic elements, now I'm in the
    planning stage of the actionscript, and this is where I'm hitting
    some trouble, so if I could barrow some actionscript pro's mind
    that would be awesome.
    My thought process is to create a movie clip and have it be
    replaced with images imported through an XML file (for easy
    updating). After this part I run into trouble, I'm planning on
    taking the MC that got replaced and duplicating it and running the
    MC's side by side, and when one goes too far to the left or right
    move it to the other end of the other MC, this way I create an
    infinite loop.
    My Questions:
    so like how would you make one of the MC's reposition it's
    self on the X axis to the end of the other movie clip once it has
    moved far enough left or right ? (also what is the method you would
    use to tell flash the limit that the MC is far enough left or right
    and it should reset it's self?)
    How would you make each thumbnail button change the image on
    the main stage upon clicking the thumbnail button when all the
    images are imported through the xml document?
    Thank you for help and time spent reading this.
    if you have any questions, please ask.
    thanks once again.
    -Mark

    Rob,
    First of all I would like to greatly thank you for all you
    have done for me. It has been so useful and such a learning
    experience getting to go through your personal code. and
    manipulating it to my personal flash. Thank you so much!
    However, I'm reaching some trouble when I try to import my
    XML file, or something is just missing.
    so here is the break down:
    in my main .fla file I have this actionscript to import your
    .as file (with modifications made to the name and package)
    var Carousel:carousel = new carousel();
    trace(Carousel);
    now that seems to import into my FLA just fine, the trace
    tells me that [object carousel] which I assume that means the
    object has loaded into the FLA.
    So anyway there is nothing on my stage in the main FLA, which
    I assume is because the XML is not getting loaded properly into the
    flash/actionscript.
    My XML (minus all the images but one):
    <icons>
    <icon image="icon1.jpg" />
    </icons>
    so this is the basic of my XML, when I import the xml into a
    more simpler file the jpgs work just fine.
    now I thoroughly went through your script examining every
    functions and var and I'm able to understand majority of it however
    parts of the import section is what confuses me, so if you could
    help me understand the script more that would be amazing.
    (the line numbers are probably off a little because I deleted
    a couple unnecessary variables for my flash)
    in line 57: urlLoader.addEventListener("complete", loaded);
    why do you have "complete" instead of Event.COMPLETE... is
    there a difference?
    in line 81 & 82: var count1:uint = source.indexOf("/") +
    1;
    var count2:uint = source.indexOf(".");
    please explain what "/" and "." means... do I replace it with
    location of the nodes in my xml?
    so yeah this is the gist of it, if you could help me figure
    out how to import my XML properly that would be great, or if you do
    not have the time do that maybe you could let me check out your
    XML, piece it all together and figure out the difference of your
    working copy and my unworking copy.
    Once again Thank you so MUCH! for taking your time in helping
    me out, I hope things are going well for ya.
    -Mark

Maybe you are looking for