Text in MovieClip

Hello,
Sorry for this stupid question, it should already have been answered a lot, but I couldn't find the answer on the forum. So here it is:
I have a movieClip "Cell" associated to a class. The cell is basically a square with a textField containing a number. This textifield is a selectable TLF text called "txtNbCell".
Here is my code :
//class Board
this.arCells = new Array();
arCells[1] = new Cell(75,475,0,"1");
arCells[2] = new Cell(75,435,0,"2");
arCells[3] = new Cell(75,395,0,"3");
//class Cell
public function Cell(pX:Number, pY:Number, pR:Number = 0, pT:String = "") {
     this.x = pX;
     this.y = pY;
     this.rotation = pR;
     this.txtNbCell.text = pT;
If I comment the line "this.txtNbCell.text = pT;", everything works properly. But if I try to change the text, I got an error #1009: Cannot access a property or method of a null object reference.
Any idea ?

Michael Maurel wrote:
The movieClip is exported in the fist frame.
and?
What's the idea with the instance name of the type?
i don't understand your question but the problem remains:  there's no textfield txtNbCell in your Cell class movieclips when your constructor executes.

Similar Messages

  • On button rollover Dynamic text and Movieclip appear

    Hi guys,
    I've got an issue - When one of my buttons is rolled over, I want text and a movieclip to appear. When the button is no longer rolled over, I want the text and movieclip to disappear.
    The way that I was going to do this was to have anchor_mc as an anchor, and upon rollover have the movieclip play from inside the anchor (as its at the exact X & Y that its needed at) and dynamic text appear.
    Questions:
    1) How do I attach mc_textbox to mc_anchor --- OR, how do I set coordinate for just where mc_textbox should show?
    2) How do I then make the movieclip disappear if the button is no longer rolled over?
    3) Is it not possible for me to merge all of the dynamic text functions into one function, using IF statements? I tried this, but couldn't work it out.
    AS3 code is attached below.
    import flash.events.MouseEvent;
    stop();
    line1.addEventListener(MouseEvent.ROLL_OVER, line_in1, false, 0, true);
    line1.addEventListener(MouseEvent.ROLL_OUT, line_out, false, 0, true);
    line2.addEventListener(MouseEvent.ROLL_OVER, line_in2, false, 0, true);
    line2.addEventListener(MouseEvent.ROLL_OUT, line_out, false, 0, true);
    line3.addEventListener(MouseEvent.ROLL_OVER, line_in3, false, 0, true);
    line3.addEventListener(MouseEvent.ROLL_OUT, line_out, false, 0, true);
    line4.addEventListener(MouseEvent.ROLL_OVER, line_in4, false, 0, true);
    line4.addEventListener(MouseEvent.ROLL_OUT, line_out, false, 0, true);
    line5.addEventListener(MouseEvent.ROLL_OVER, line_in5, false, 0, true);
    line5.addEventListener(MouseEvent.ROLL_OUT, line_out, false, 0, true);
    line6.addEventListener(MouseEvent.ROLL_OVER, line_in6, false, 0, true);
    line6.addEventListener(MouseEvent.ROLL_OUT, line_out, false, 0, true);
    line7.addEventListener(MouseEvent.ROLL_OVER, line_in7, false, 0, true);
    line7.addEventListener(MouseEvent.ROLL_OUT, line_out, false, 0, true);
    line8.addEventListener(MouseEvent.ROLL_OVER, line_in8, false, 0, true);
    line8.addEventListener(MouseEvent.ROLL_OUT, line_out, false, 0, true);
    line9.addEventListener(MouseEvent.ROLL_OVER, line_in9, false, 0, true);
    line9.addEventListener(MouseEvent.ROLL_OUT, line_out, false, 0, true);
    function line_in1(e:MouseEvent):void
            line_output.text = "This is a test made by the MonkeyTest that has previously messed up\n        And testing a new line";
    function line_in2(e:MouseEvent):void
            line_output.text = "up messed previously has that MonkeyTest the by made test a is This";
    function line_in3(e:MouseEvent):void
            line_output.text = "This is a test made by the MonkeyTest that has previously messed up\n        And testing a new line";
    function line_in4(e:MouseEvent):void
            line_output.text = "up messed previously has that MonkeyTest the by made test a is This";
    function line_in5(e:MouseEvent):void
            line_output.text = "This is a test made by the MonkeyTest that has previously messed up\n        And testing a new line";
    function line_in6(e:MouseEvent):void
            line_output.text = "up messed previously has that MonkeyTest the by made test a is This";
    function line_in7(e:MouseEvent):void
            line_output.text = "This is a test made by the MonkeyTest that has previously messed up\n        And testing a new line";
    function line_in8(e:MouseEvent):void
            line_output.text = "up messed previously has that MonkeyTest the by made test a is This";
    function line_in9(e:MouseEvent):void
            line_output.text = "up messed previously has that MonkeyTest the by made test a is This";
    function line_out(e:MouseEvent):void
            line_output.text = "";
            var mc= new mc_empty(); addChild(mc);

    It isn't relly clear to me what you have versus what you want, so these answers may be equally unclear to you.
    1. One way to join them together is to maually place one inside the other while authoring the file.  Another way is to use addChild to add the text mc to the anchor...  mc_anchor.addChild(mc_textbox);  To control where the text mc appears you can set its x and y properties.using actionscript... mc_textbox.x = 0;
    2. To make the movieclip disappear you can set its visible property to false... mc_anchor.visible = false;
    3. You can probably reduce that code substantially, though it partly depends on what variations there are really going to be in the text that displays for each rollover.  For now, I'll assume the text will be entirely different for each...
    for(var i:uint=1; i<10; i++){
         this["line"+String(i)].addEventListener(MouseEvent.ROLL_OVER, line_in, false, 0, true);
         this["line"+String(i)].addEventListener(MouseEvent.ROLL_OUT, line_out, false, 0, true);
    function line_in(e:MouseEvent):void {
         var lineTarget:MovieClip = MovieClip(e:currentTarget);
          // could use a switch instead of the if's in series if you know what a switch is
         if(lineTarget == line1){
              // do things for line1
         } else if(lineTarget == line2){
              // do things for line2
         ) else if.... etc

  • How To Make Text Disappear When Mouse is On a Button?

    Hello,  I'm completely new to Flash and well I need some help. I created a page that has static text in the center.
    The page has buttons on side and when I rollover a button text appears, but the problem is that when I rollover a button, the static text in the center is there and I want to hide it as I can't read anything because the texts are overlapped.
    How do I make the text in the center disappear/hide when I rollover a button and how do I make it reappear when the the mouse is off the button?
    I hope what I am explaining makes sense.

    You can assign onRollOver and onRollOut code to the buttons to make the text dispappear, but you'll need to make the text a movieclip with an instance name that you can use to target it to turn it invisible.  In the simple example below, the button has an instance name of "btn" and the text movieclip has an instance name of "text_mc"
    btn.onRollOver = function(){
          text_mc._visible = false;
    btn.onRollOut = function(){
          text_mc._visible = true;

  • Loading an external image (from file system) to fla library as MovieClip symbol.

    Hi everyone,
    I am new to actionscript and Flash.
    I have been working on code updation project wherein initially we had an image and text as movieclips in fla library. The image and the text are read by the actionscript program which then creates an animation.
    For Example:
    // Picture
    // _imageMC: Name of the Movie Clip in the libary which
    // contains the picture.
    var _imageMC:String = "polaroid";
    This is later on used by another actionscript class as follows to finally create the animation.
    var _mcPolaroid:MovieClip = this._mcBg.attachMovie(this._polaroid, "polaroid_mc", this._mcBg.getNextHighestDepth());
    Now the problem here is when one needs to update the image or text, one needs to go and open the fla file andmanually change the image attached to the movieClip (polaroid).
    I want to ease the updation process by giving the url of the image in an XML file. Read the image url from the xml and load this image in the library of the fla as movieclip. This, i think, will result in less code change and improve the updation of the final animation image.
    The problem i am facing is not been able to figure out how can i change the image (after fetching its URL) to a movieclip and then load it in the library?
    Thank you kindly in advance,
    Varun

    This is the AS3 forum and you are posting with regards to AS2 code.  Try posting in the AS2 forum...
    http://forums.adobe.com/community/flash/flash_actionscript
    As for the solution you seem to want.  You cannot dynamically add something to the library during runtime.  To add an image during runtime you would need to use the MovieClip.loadMovie() or MovieClipLoader.loadClip() methods.  You could have the movieclip pre-arranged in the library, but to add the image dynamically via xml information you need to load it into a movieclip, not the library.

  • Loading an external image (from file system) to fla library as MovieClip symbol using ActionScript.

    Hi everyone,
    I am new to actionscript and Flash.
    I have been working on code updation project wherein initially we had an image and text as movieclips in fla library. The image and the text are read by the actionscript program which then creates an animation.
    For Example:
    // Picture
    // _imageMC: Name of the Movie Clip in the libary which
    // contains the picture.
    var _imageMC:String = "polaroid";
    This is later on used by another actionscript class as follows to finally create the animation.
    var _mcPolaroid:MovieClip = this._mcBg.attachMovie(this._polaroid, "polaroid_mc", this._mcBg.getNextHighestDepth());
    Now the problem here is when one needs to update the image or text, one needs to go and open the fla file andmanually change the image attached to the movieClip (polaroid).
    I want to ease the updation process by giving the url of the image in an XML file. Read the image url from the xml and load this image in the library of the fla as movieclip. This, i think, will result in less code change and improve the updation of the final animation image.
    The problem i am facing is not been able to figure out how can i change the image (after fetching its URL) to a movieclip and then load it in the library?
    Thank you kindly in advance,
    Varun

    The following was my attempt: (i created a new MovieClip)
    this.createEmptyMovieClip("polaroidTest", this.getNextHighestDepth());
    loadMovie("imagefile.jpg", polaroidTest)
    var _imageMC:String = "polaroidTest";
    This mentioned variable _imageMC is read by a MovieClip class(self created as follows)
    /////////////////////////////// CODE STARTS //////////////////////////////////////
    class as.MovieClip.MovieClipPolaroid {
    private var _mcTarget:MovieClip;
    private var _polaroid:String;
    private var _mcBg:MovieClip;
    private var _rmcBg:MovieClip;
    private var _w:Number;
    private var _h:Number;
    private var _xPosition:Number;
    private var _yPosition:Number;
    private var _border:Number;
    * Constructor
        function MovieClipPolaroid(mcTarget:MovieClip, polaroid:String) {
    this._mcTarget = mcTarget;
    this._polaroid = polaroid;
    init();
    * initialise the polaroid movieclip and reflecting it
        private function init():Void {
    this._border = 10;
    this.initSize();
    this.setPosition(48,35);
    this.createBackground();
    var _mcPolaroid:MovieClip = this._mcBg.attachMovie(this._polaroid, "polaroid_mc", this._mcBg.getNextHighestDepth());
    _mcPolaroid._x = _border;
    _mcPolaroid._y = _border;
    var _rmcPolaroid:MovieClip=this._rmcBg.attachMovie(this._polaroid,"rpolaroid_mc", this._rmcBg.getNextHighestDepth());
    _rmcPolaroid._yscale *=-1;
    _rmcPolaroid._y = _rmcPolaroid._y + _h + _border ;
    _rmcPolaroid._x =_border;
    * create the background for the polaroid
    private function createBackground():Void {
    this._mcBg = _mcTarget.createEmptyMovieClip("target_mc",_mcTarget.getNextHighestDepth());
    this._rmcBg = _mcTarget.createEmptyMovieClip("rTarget_mc", _mcTarget.getNextHighestDepth());
    fill(_mcBg,_w+2*_border,_h+2*_border,100);
    fill(_rmcBg,_w+2*_border,_h+2*_border,10);
    placeBg(_mcBg,_w+2*_border,_yPosition);
    placeBg(_rmcBg,_w+2*_border,_h+2*_border+_yPosition);
    * position the background
    private function placeBg(mc:MovieClip,w:Number,h:Number) : Void {  
        mc._x = Stage.width - w - _xPosition;
    mc._y = h;
    * paint the backgound
    private function fill(mc:MovieClip,w:Number,h:Number, a:Number): Void {
    mc.beginFill(0xFFFFFF);
    mc.moveTo(0, 0);
    mc.lineTo(w, 0);
    mc.lineTo(w, h);
    mc.lineTo(0, h);
    mc.lineTo(0, 0);
    mc.endFill();
    mc._alpha=a;
    * init the size of the polaroid
    private function initSize():Void {
    var mc:MovieClip =_mcTarget.createEmptyMovieClip("mc",_mcTarget.getNextHighestDepth());
    mc.attachMovie(this._polaroid,"polaroid_mc", _mcTarget.getNextHighestDepth());
    this._h = mc._height;
    this._w = mc._width;
    removeMovieClip(mc);
    mc = null;
    * sets the position of the polaroid
    public function setPosition(xPos:Number,yPos:Number):Void {
    this._xPosition = xPos;
    this._yPosition = yPos;
    * moving in
    public function moveIn():Tween {
    var mc:MovieClip = this._mcTarget;
    mc._visible=true;
    var tween:Tween = new Tween(mc, "_x", Strong.easeOut, 0, 0, 1, true);
    var tween:Tween = new Tween(mc, "_y", Strong.easeOut, 200, 0, 1, true);
    var tween:Tween = new Tween(mc, "_xscale", Strong.easeOut, 30, 100, 1, true);
    var tween:Tween = new Tween(mc, "_yscale", Strong.easeOut, 30, 100, 1, true);
    var tween:Tween = new Tween(mc, "_alpha", Strong.easeOut, 0, 100, 1, true);
    return tween;
    * moving in
    public function moveOut():Tween {
    var mc:MovieClip = this._mcTarget;
    var tween:Tween = new Tween(mc, "_alpha", Strong.easeIn, 99, 0, 1, true);
    var tween:Tween = new Tween(mc, "_x", Strong.easeIn,0, 1000, 1, true);
    var tween:Tween = new Tween(mc, "_y", Strong.easeIn, 0, -50, 1, true);
    var tween:Tween = new Tween(mc, "_xscale", Strong.easeIn, 100, 50, 1, true);
    var tween:Tween = new Tween(mc, "_yscale", Strong.easeIn, 100, 50, 1, true);
    return tween;
    /////////////////////////////// CODE ENDS ///////////////////////////////////////
    As in the current case, the name of the movieclip which has the image (originally polaroid) is being read through the variable _imageMC which we hadd given the value "polaroidTest".
    The animation shows no image even when i have inserted the correct url (i m sure this step isn't wrong).
    Any clues?

  • How displaying text in child?

    -I got two movie clips in library (s1 and s2).
    -Got text filed in each movie clips ($text1 and $text2)
    I wrote the code to show the texts of two movie clips.
    However, s1 showed the text, s2 doesn't. Why?
    Attachment for reference.http://hotfile.com/dl/126771818/ed3ea02/test-addchild-display_text-cs4.fla.html
    import flash.display.MovieClip;
    var a:MovieClip =new s1();
    a.x=stage.stageWidth/2;
    a.y=stage.stageHeight/2;
    addChild(a);
    var b1:MovieClip = new s2();
    b1.x=stage.stageWidth/2-150;
    b1.y=stage.stageHeight/2-150;
    a.addChild(b1);
    a.$text1.text="a";
    a.b1.$text2.text="b";

    Just to demo the first approach I mentioned using getChild...()-type methods...
    var a:MovieClip =new s1();
    a.x=stage.stageWidth/2;
    a.y=stage.stageHeight/2;
    addChild(a);
    var b1:MovieClip = new s2();
    b1.name = "b1_s2_mc";
    b1.x=stage.stageWidth/2-150;
    b1.y=stage.stageHeight/2-150;
    a.addChild(b1);
    a.$text1.text="a";
    MovieClip(a.getChildByName("b1_s2_mc")).$text2.text="b";

  • How to add a MovieClip in current fla

    Like the example Rob Dillon shew me: http://www.ddg-designs.com/downloads/textOverVideo2.zip How to add the text window movieClip? I tried: 1. new as3 project 2. add component -> movieClip -> instance name "aa" but I couldn't find where the new movieClip "aa" was. Please advise. Thanks,

    Normally when you create a new movieclip the window opens to the timeline of the movieclip such that the blank screen in front of you would be the inside of the movieclip.  If you look in the library you should see it there as well.

  • Fade in text link on top of image

    Hi,
    I am fairly new to flash so forgive me if this is an easy
    question. I have a flash header that will be made up of an image
    being faded in then out to be replaced by another image etc for up
    to four images. I have been able to do this fairly easily but what
    I would like to do next is when each image has fully faded in, I
    then fade in some text on top of the image which will become a link
    to a page on the site. Each of the four images will have different
    text and links associated with it.
    Anyone got any suggesstions on how I can achieve this look
    and functionality ?
    Cheers
    Macca

    Make the text a movieclip or a button. Then you can fade it
    and use it as a button.

  • Movieclip button keeps disappearing for some reason.

    I created our website using Actionscript 2.0 and on several of our pages there is a drop-down text box that has a "close" button on it, which is just a movieclip located inside the text box movieclip.  For some reason, if you stay on a page for a few minutes the close button disappears.  The hand still shows up when you hover over where it was at and you can still click on it, but it just turns invisible.  I'm not sure what's causing this.  Any suggestions?
    The website is:  www.klaesimage.com
    Thanks,
    Shaun

    Rothrock wrote:
    My guess is that you have some kind of loop that adjusts the _alpha to brighten it up that is like this:
    myButton.onRollover=function(){
    this.onEnterFrame=function(){
    this._alpha+=10;
    And you don't have a conditional to say, "when alpha reaches 100 stop adding more."
    So what happes is that the alpha value goes about 100 and when it gets to something like 2^15 it wraps around and becomes an incredibly low negative number. If you wait another few minutes it should eventually get back to positive values!
    Of course the best bet would be to put in some conditionals to control that it doesn't go above/below 100/0.
    After watching it for a while longer I saw that it does cycle.  I'm not sure why because its alpha should just stay at 100 once it's on that frame, the dissolve up is from a motion tween where the entire contents of the text box go from 0 alpha to 100 alpha over 10 or so frames, but once there on the frame where it stops there shouldn't be any changes to the alpha.

  • Events, Variables and Input Text

    Hi,
    I'm not new to Flash or AS3 but I've never really made anything too complex. I'm making a Flash game and getting to know Variables for the first time. The tutorials online confuse me because they're mostly geared towards AS2 and I bought this book (which is awesome) Game Design with Flash, but it only covers variables involving numbers and a guessing game.
    All I want right now is a field to enter your name and below, whatever the user has entered, will show up in a Dynamic text field that will go, "Oh, so your name is (whatever)?" I understand that the information that the user types into the Input Text Field has to be entered in somehow, so do I need to make a function to make it work with a button? Right now I can type in the Input but nothing shows up in the Dynamic text field.
    I borrowed an AS3 example from elsewhere on this forum and added my own Instance names. I also wanted to know, how can I call up the user's name throughout the game? Just calling that same variable up?
    Here is what I have:
    stop();
    var myName:String;
    myName = userName.text;
    confirm_txt.text = "So your name is "+ myName;
    I get no errors but the Dynamic text box isn't showing what I'm typing... How do I go about "entering" the name so it shows up and I can call it up anytime throughout the game?
    Thank you so much in advance for any help offered!

    "It sounds like the same concept of a class, so if a class is a pot, everything in it can be what pertains to the pot."
    Well, there one important thing you need to keep in mind when dealing with Flash. There are classes and display lists. Classes have properties and methods and display lists have children.
    For example,
    var myClip:MovieClip = new MovieClip();
    var mySprite:Sprite = new Sprite();
    myClip.addChild(mySprite);
    Now, this is important:
    you can
    trace(myClip.x) - because is x a documented property of MovieClip class
    BUT
    you cannot
    trace(myClip.mySprite) because although mySprite is a child of myClip, IT IS NOT A PROPERTY of myClip as it is not a property of MovieClip class.
    In other words, display list of a DisplayObjectContainer is sort of independent property/feature that doesn't fall into conventional realm of class capabilties. This special feature is addressed and children are manipulated in a special, peculiar to Flash manner only.
    Using pot analogy, display list is a space where you can put DisplayObjects. Objects that are put into this space do not belong to the instnace but just temporarily occupy it.
    Here is a little game (let's name it "move vegies between pots") that may help you to get feel of parent/child relationships. Click on vegies and observe how they behave relative to their parents:
    import flash.display.Graphics;
    import flash.display.MovieClip;
    import flash.display.Sprite;
    import flash.events.MouseEvent;
    import flash.text.TextField;
    var apple:MovieClip = vegie("apple");
    var beet:MovieClip = vegie("beet");
    var onion:MovieClip = vegie("onion");
    var pear:MovieClip = vegie("pear");
    var bigPot:Sprite = makePot(250, 250);
    var mediumPot:Sprite = makePot(200, 200);
    var smallPot:Sprite = makePot(150, 150);
    addChild(bigPot);
    addChild(mediumPot);
    addChild(smallPot);
    bigPot.x = 20;
    bigPot.y = 20;
    mediumPot.x = bigPot.x + bigPot.width + 50;
    mediumPot.y = bigPot.y + bigPot.height - mediumPot.height;
    smallPot.x = mediumPot.x + mediumPot.width + 50;
    smallPot.y = bigPot.y + bigPot.height - smallPot.height;
    var vegies:Array = [apple, beet, onion, pear];
    var pots:Array = [bigPot, mediumPot, smallPot];
    putVegies();
    * Places vegies into big pot
    function putVegies():void {
         for each(var veg:MovieClip in  vegies) {
              bigPot.addChild(veg);
              // bigPot has index 0 in pots Array
              veg.parentIndex = 0;
              veg.mouseChildren = false;
              veg.buttonMode = veg.useHandCursor = true;
              veg.x = veg.width + Math.random() * (bigPot.width - veg.width * 3);
              veg.y = veg.height + Math.random() * (bigPot.height - veg.height * 3);
              veg.addEventListener(MouseEvent.CLICK, onClick);
    * listener to clicking on vegies
    * chooses a new random parent
    * @param     e
    function onClick(e:MouseEvent):void {
         var target:MovieClip = e.currentTarget as MovieClip;
         // new parent random index
         var parentIndex:int = Math.round(Math.random() * (pots.length - 1));
         var newParent:Sprite = pots[parentIndex];
         newParent.addChild(target);
         target.x = target.width + Math.random() * (newParent.width - target.width * 3);
         target.y = target.height + Math.random() * (newParent.height - target.height * 3);
    * Makes vegie
    * @param     text - vegie label
    * @return
    function vegie(text:String):MovieClip {
         var label:TextField = new TextField();
         label.autoSize = "left";
         label.text = text;
         label.x = - label.width / 2;
         label.y = - label.height / 2;
         var s:MovieClip = new MovieClip();
         var g:Graphics = s.graphics;
         g.beginFill(0xffffff * Math.random());
         g.drawCircle(0, 0, (label.width / 2) + 5);
         g.endFill();
         s.addChild(label);
         return s;
    * Draws pot outline
    * @param     w
    * @param     h
    * @return
    function makePot(w:Number, h:Number):Sprite {
         var edge:Number = 10;
         var s:Sprite = new Sprite();
         var g:Graphics = s.graphics;
         g.lineStyle(2, 0x000000);
         g.moveTo(0, 0);
         g.lineTo(w, 0);
         g.lineTo(w - edge, edge);
         g.lineTo(w - edge, h - edge);
         g.curveTo(w - edge, h, w - edge * 2, h);
         g.lineTo(edge * 2, h);
         g.curveTo(edge, h, edge, h - edge );
         g.lineTo(edge, edge);
         g.lineTo(0, 0);
         return s;

  • Static text as mask doesn't work

    I'm creating a button that uses static text as both content
    and as a
    mask (to create an inner shadow effect). The static text is
    in a
    symbol. It looks perfect in the IDE, but when I test the
    movie or
    publish it, the mask doesn't work. I originally had the text
    in a
    graphic symbol and that caused the mask to be completely
    ignored. I
    changed the symbol to a MovieClip, and that behaves
    differently. The
    mask is no longer ignored, but now the mask layer itself
    appears and
    covers up the other layers.
    I've googled for this problem and have seen many comments
    about it. The
    typical solutions seem to be to convert the text to a symbol
    (already
    done) and use static text (already done). Yet it still
    doesn't work.
    I'm using Flash MX 2004.
    Please help. Thanks.

    apply it with actionscript,
    make your text a movieclip and give it a name like "textClip"
    then
    make your mask a movieclip and give it an instance name like
    "textMask" and use this code
    textClip.setMask(textMask);
    to disable the mask with actionscript use:
    textClip.setMask(null);
    good luck!

  • Lock aspect ratio of resizeable box

    Hey guys,
    I have made a resizeable box that you can resize using handles on all four corners
    I have tl (top left handle), tr (top right handle), bl (bottom left handle) and br (bottom right handle)
    Its rather difficult to explain. See the picture attached, the blue arrows are where the mouse could move and the green arrows are where the boxes should go
    For now let's concentrate on moving the tl handle so that when it is moved left or downwards it gets smaller, towards the br handle
    I've have tried this:
    tl.y = tl.x
    tl.x = tl.y
    bl.x = tl.x
    tr.y = tl.y
    But that will only resize the box when moving the mouse in one axis
    Any ideas?
    Thanks
    Chris

    Here is one of the ways to approach it. Just make this class a document class:
    package
        import flash.display.Graphics;
        import flash.display.MovieClip;
        import flash.display.Sprite;
        import flash.events.Event;
        import flash.events.MouseEvent;
        import flash.text.TextField;
        import flash.text.TextFormat;
        public class ResizeBox extends Sprite
            private var box:Sprite;
            private var bg:Graphics;
            private var tl:MovieClip;
            private var tr:MovieClip;
            private var bl:MovieClip;
            private var br:MovieClip;
            private var currentHandle:MovieClip;
            public function ResizeBox()
                init();
            private function init():void
                box = new Sprite();
                bg = box.graphics;
                addChild(box);
                drawHandles();
            private function drawHandles():void
                tl = handle("tl");
                tr = handle("tr");
                bl = handle("bl");
                br = handle("br");
                tl.dependX = bl;
                tl.dependY = tr;
                tr.dependX = br;
                tr.dependY = tl;
                bl.dependX = tl;
                bl.dependY = br;
                br.dependX = tr;
                br.dependY = bl;
                addChild(tl);
                addChild(tr);
                addChild(bl);
                addChild(br);
                tl.x = bl.x = stage.stageWidth * .5 - 100;
                tl.y = tr.y = stage.stageHeight * .5 - 100;
                bl.y = br.y = stage.stageHeight * .5 + 100;
                br.x = tr.x = stage.stageWidth * .5 + 100;
                drawBox();
            private function drawBox():void
                bg.clear();
                bg.beginFill(0x000000);
                bg.moveTo(tl.x, tl.y);
                bg.lineTo(tr.x, tr.y);
                bg.lineTo(br.x, br.y);
                bg.lineTo(bl.x, bl.y);
                bg.endFill();
            private function handle(text:String):MovieClip
                var t:TextField = new TextField();
                t.defaultTextFormat = new TextFormat("Arial", 10);
                t.multiline = t.wordWrap = false;
                t.autoSize = "left";
                t.text = text;
                var s:MovieClip = new MovieClip();
                s.graphics.beginFill(0xff0000);
                s.graphics.drawRect(-6, -6, 12, 12);
                s.addChild(t);
                t.x = -t.width * .5;
                t.y = -t.height * .5;
                s.buttonMode = true;
                s.mouseChildren = false;
                s.addEventListener(MouseEvent.MOUSE_DOWN, onHandleDown);
                return s;
            private function onHandleDown(e:MouseEvent):void
                stage.addEventListener(MouseEvent.MOUSE_UP, onMouseUp);
                addEventListener(Event.ENTER_FRAME, onDrag);
                currentHandle = MovieClip(e.currentTarget);
                currentHandle.startDrag();
            private function onMouseUp(e:MouseEvent):void
                stopDrag();
                stage.removeEventListener(MouseEvent.MOUSE_UP, onMouseUp);
                removeEventListener(Event.ENTER_FRAME, onDrag);
                currentHandle = null;
            private function onDrag(e:Event):void
                currentHandle.dependX.x = currentHandle.x;
                currentHandle.dependY.y = currentHandle.y;
                drawBox();

  • Set an undefined Loaded variable's alpha to 0

    Hi, I'm trying creating a flash navigation bar that can be edited via a simple text file. I'm able to load my different variables properly but i also want to give the user the ability to remove links. I can simply leave the variable from the text file blank and and have the text in the swf disappear but i also want to be able to set the alpha of the movieclip behind the text to zero when the variable is left blank. Alternatively, even if the user could simply set the variable to the string "Blank" and both the alpha of the dynamic text and movieclip would change to zero that would be functional as well. Here is the code i have so far.
    NavLoadVar = new LoadVars();
    NavLoadVar.load("navigation.txt");
    NavLoadVar.onLoad = function() {
         b1.text = NavLoadVar.b1text;
         b2.text = NavLoadVar.b2text;
         b3.text = NavLoadVar.b3text;
         b4.text = NavLoadVar.b4text;
         b5.text = NavLoadVar.b5text;
         b6.text = NavLoadVar.b6text;
         b7.text = NavLoadVar.b7text;
         b8.text = NavLoadVar.b8text;
    if (NavLoadVar.b1text == "Blank") {
         divider1._alpha = 0;

    Something like the following should work...
    NavLoadVar.onLoad = function() {
         for(i=1; i<9; i++){
              if (NavLoadVar["b"+i+"text"] == "Blank") {
                   this["divider"+i]._alpha = 0;
              } else {
                   this["b"+i].text = NavLoadVar["b"+i+"text"] ;

  • Changing a font across the frames

    Hi all
    Novice here. I have created an animation where I have pictures and text accompanying the pictures sliding in and out. However, I want to change the font of the text across the entire animation. What is the easiest way to do this? I have found when I have tried it, (changing the font in the text box) that sometimes it throws the whole animation out for each key frame that has that text (if this makes any sense). In other words, suppose I change the font in keyframe 1, the change it at the next keyframe, sometimes the second keyframe is no longer consistent with the first, perhaps only slightly and therefore the animation can run a bit choppy as it goes from keyframe to keyframe.  Any ideas? All help appreciated.
    thanks
    Metta

    If you place the text into movieclips and animate the movieclips, you shouldn't have any issue like that, and you would only have to change the font once in the movieclip, not in every frame that has it.

  • Error #1009: Help needed

    Hello everyone,
    I'm looking for some help with an error I'm getting:
    Error #1009: Cannot access a property or method of a null object reference
    Now, I know approximately what it means, I just can't find where exactly the problem is or how to fix it.
    I must warn tho, my code is a bit chaotic, had a rough start and now I'm just trying to finish before the deadline, and with my time left I'm gonna clean up the code.
    I think it's best if I send the entire flash project in a zip so if you are willing to help just let me know how to reach you
    Thanks in advance.
    Davey

    I fixed the errors, not getting any anymore, think the problem was adding an event listener to a button on stage in the subclass constructor. Seeing as I first call the function and then pass the button from main class to sub class, the button wasn't set yet ( I think ). However, the errors are gone, but my event listeners don't seem to be doing anything. I'll paste all my code
    Main.as, the classes used for this are:addClasses(), removeEvents(), addEvents(), addButtonEvents(), menuKeuzeNext(it just calls addClasses when input control is finished)
    [AS]
    package
        import flash.display.MovieClip;
        import flash.display.Shape;
        import flash.display.DisplayObject;
        import flash.geom.ColorTransform;
        import flash.events.MouseEvent;
        import flash.events.Event;
        import flash.display.*;
          import flash.net.*;
        public class Main extends MovieClip
           //XML wordt ingeladen en geprocessed in aparte klasse
           //private var xmlLoad = new XMLLoad;
            //Variabelen om XML in te laden
                private static var url:String = "drawings.xml";
                private var contentXML:XML;
                private var contentXMLURL:URLRequest;
                private var contentXMLLoader:URLLoader;
            //Arrays om data van XML in op te slaan
                private var titles:Array = new Array;
                private var authors:Array = new Array;
                private var locations:Array = new Array;
                private var currentChoice:uint = 0;
                public var naam:String = new String;
                public var bedragString:String = new String;
                public var bedrag:uint = new uint;
            //swf loader variabelen
                private var drawRequest:URLRequest;
                private var drawLoader:Loader = new Loader();
            //Alle objecten die in de movieclip inputMenu zitten beschikbaar maken
                private var naamInput:TextField;
                private var bedragInput:TextField;
                private var naamLeegmc:MovieClip
                private var naamLeeg:TextField;
                private var bedragLeegmc:MovieClip;
                private var bedragLeeg:TextField;
            //Klassen voor draw en erase laden in frame 2
                public var eraserClass:Eraser;
                public var spraycanClass:Spraycan;
            //Welke tool is momenteel actief?
                public static var activeEvents:Array;
            public function Main():void
                stop();
                /*Event listeners worden toegevoegd in de Action layer, per frame.
                Als je ze niet inlaadt bij de bijbehorende frame krijg je errors
                   omdat de buttons waar je de event listener aan hangt, zogezegt nog niet bestaat)*/
                //addEventListeners();
                XMLLoad();
            private function addClasses():void
                eraserClass = new Eraser();
                eraserClass.setDrawBoard(drawBoard);
                eraserClass.setButton(eraser);
                eraserClass.setDrawSize(drawSize);
                trace("if");
                spraycanClass = new Spraycan();
                spraycanClass.setDrawBoard(drawBoard);
                spraycanClass.setButton(spraycan);
                spraycanClass.setDrawSize(drawSize);
                spraycanClass.setColorsMC(colors);
                spraycanClass.setSizePanel(sizePanel);
                addButtonEvents();
            //removeEventListeners voor van actieve tool te wisselen
            public static function removeEvents():void
                if(activeEvents != null)
                    for(var i = 0; i < activeEvents.length; i++)
                        if(activeEvents[i].movieclip.hasEventListener(activeEvents[i].type))
                        activeEvents[i].movieclip.removeEventListener(activeEvents[i].type, activeEvents[i].listener);
                    activeEvents = new Array();
                    trace("niet leeg");
                } else {
                    trace("leeg");
            //addEventListeners voor actieve tool te starten
            public static function addEvents(movieclip:MovieClip,type:String, listener:Function):void
                activeEvents = new Array();
                movieclip.addEventListener(type,listener);
                activeEvents.push({movieclip:movieclip, type:type, listener:listener});
            public function addButtonEvents():void
                eraser.addEventListener(MouseEvent.MOUSE_DOWN, eraserClass.eraserTool);
                spraycan.addEventListener(MouseEvent.MOUSE_UP, spraycanClass.spraycanTool);
                colors.addEventListener(MouseEvent.MOUSE_UP, spraycanClass.chooseColor);
                sizePanel.addEventListener(MouseEvent.MOUSE_UP, spraycanClass.changeDrawSize);
            private function menuKeuzeBack(event:MouseEvent):void
                inputMenu.visible = false;
            public function callMenu(event:MouseEvent):void
                inputMenu.visible = true;
                MovieClip(inputMenu).keuzeStart.addEventListener(MouseEvent.MOUSE_UP, menuKeuzeNext);
                MovieClip(inputMenu).keuzeAnnuleer.addEventListener(MouseEvent.MOUSE_UP, menuKeuzeBack);
                hideAlerts();
            private function hideAlerts():void
                MovieClip(inputMenu).naamLeegmc.visible = false;
                MovieClip(inputMenu).naamLeeg.visible = false;
                MovieClip(inputMenu).bedragLeegmc.visible = false;
                MovieClip(inputMenu).bedragLeeg.visible = false;
            private function menuKeuzeNext(event:MouseEvent):void
                hideAlerts();
                naam = MovieClip(inputMenu).naamInput1.text;
                bedragString = MovieClip(inputMenu).bedragInput1.text;
                bedrag = int(bedragString);
                //alle invoer alerts terug op onzichtbaar zetten voor als men bv naam verbeterd heeft maar bedrag nog steeds incorrect is, anders blijft alert van naam ook staan.
                //invoercontrole
                if(naam == "")
                    showAlert("leeg", "naam")
                } else if(naam.length > 30)
                    showAlert("te lang", "naam");
                if(bedrag == 0)
                    showAlert("Bedrag is leeg", "bedrag");
                } else if(bedrag < 2.5)
                    showAlert("Bedrag moet minstens 2,5 euro zijn", "bedrag");
                if(naam.length < 30 && bedrag > 2.5 && naam !="")
                    gotoAndStop(2);
                    inputMenu.visible = false;
                    newImageMC.visible = false;
                    addClasses();
            private function showAlert(error, input):void
                if (input=="naam")
                    MovieClip(inputMenu).naamLeeg.text = "Naam is " + error;
                    MovieClip(inputMenu).naamLeegmc.visible = true;
                    MovieClip(inputMenu).naamLeeg.visible = true;
                if (input=="bedrag")
                    MovieClip(inputMenu).bedragLeeg.text = error;
                    MovieClip(inputMenu).bedragLeegmc.visible = true;
                    MovieClip(inputMenu).bedragLeeg.visible = true;
            private function prevDrawing(event:MouseEvent):void
                //Als je bij de eerste foto bent en je drukt op vorige afbeelding kom je op de laatste, anders ga je eentje terug
                if(currentChoice == 0)
                    currentChoice = titles.length-1;
                } else {
                    currentChoice -= 1;
                processXML();
            private function nxtDrawing(event:MouseEvent):void
                //Als je bij de laatste foto bent en je drukt op volgende afbeelding kom je op de eerste, anders ga je eentje vooruit
                if(currentChoice == titles.length-1)
                    currentChoice = 0;
                } else {
                    currentChoice += 1;
                processXML();
            private function newUserF(event:MouseEvent):void
                newImageMC.visible=true;
                MovieClip(inputMenu).naamInput1.text = "";
                MovieClip(inputMenu).bedragInput1.text = "";
                MovieClip(newImageMC).newImageB.addEventListener(MouseEvent.MOUSE_UP, newImage);
                MovieClip(newImageMC).currentImageB.addEventListener(MouseEvent.MOUSE_UP,currentImage);
            private function newImage(event:MouseEvent):void
                gotoAndStop(1);
                //addEventListeners();
                processXML();
            private function currentImage(event:MouseEvent):void
                MovieClip(newImageMC).newImageB.removeEventListener(MouseEvent.MOUSE_UP, newImage);
                MovieClip(newImageMC).currentImageB.removeEventListener(MouseEvent.MOUSE_UP,currentImage) ;
                newImageMC.visible = false;
                inputMenu.visible = true;
            public function XMLLoad():void
                //XML inladen en naar functie xmlLoaded gaan wanneer deze ingeladen is
                contentXMLURL = new URLRequest(url);
                contentXMLLoader = new URLLoader(contentXMLURL);
                contentXMLLoader.addEventListener(Event.COMPLETE, xmlLoaded);
            private function xmlLoaded(event:Event):void {
                //XML in variabele steken
                contentXML = new XML(event.target.data);
                contentXML.ignoreWhite = true;
                for (var i = 0; i < contentXML.DRAWING.length(); i++)
                    titles[i] = contentXML.DRAWING[i].TITLE;
                    authors[i] = contentXML.DRAWING[i].AUTHOR;
                    locations[i] = contentXML.DRAWING[i].LOCATION;
                processXML();
            private function processXML():void
                titleText.text = titles[currentChoice];
                authorText.text = authors[currentChoice];
                if (drawLoader.stage)
                    choiceBoard.removeChild(drawLoader);
                if (currentChoice == 0)
                } else {
                    drawRequest = new URLRequest(locations[currentChoice]);
                    drawLoader.load(drawRequest);
                    drawLoader.contentLoaderInfo.addEventListener(Event.COMPLETE, loadComplete);
            private function loadComplete(event:Event):void
                choiceBoard.addChild(drawLoader);
                drawLoader.x= -421/2;
                drawLoader.y= -297/2;
                drawLoader.content.height = 297;
                drawLoader.content.width = 421;
    [/AS]
    Spraycan.as, class for drawing
    [AS]
    package
        import flash.display.MovieClip;
        import flash.display.Shape;
        import flash.display.DisplayObject;
        import flash.display.BitmapData;
        import flash.events.MouseEvent;
        public class Spraycan extends MovieClip
            private var sprayCan:Shape;
            private var spraycan:MovieClip;
            //Ik gebruik de bitmapdata om de RGB waarde te krijgen
            private var colorsBmd:BitmapData;
            //Vars voor kleur te kiezen.
            private var pixelValue:uint;
            private var activeColor:uint = 0x663399;
            private var drawSize:MovieClip;
            private var colors:MovieClip;
            private var sizePanel:MovieClip;
            private var drawBoardmc:MovieClip;
            public function Spraycan():void
            /*public function eventLists():void
                spraycan.addEventListener(MouseEvent.MOUSE_UP, spraycanTool);
                colors.addEventListener(MouseEvent.MOUSE_UP, chooseColor);
                sizePanel.addEventListener(MouseEvent.MOUSE_UP, changeDrawSize);
                Main.addButtonEvents(spraycan, MouseEvent.MOUSE_DOWN, spraycanTool);
                Main.addButtonEvents(colors, MouseEvent.MOUSE_DOWN, chooseColor);
                Main.addButtonEvents(sizePanel
            public function spraycanTool(e:MouseEvent):void
                //convert movieclip 'colors' naar bitmapdata
                convertToBMD();
                //Actieve tool stoppen
                Main.removeEvents();
                //Listeners toevoegen aan het 'board' MovieClip, om er in te tekenen
                Main.addEvents(drawBoardmc, MouseEvent.MOUSE_DOWN, startSpraycan);
                Main.addEvents(drawBoardmc, MouseEvent.MOUSE_DOWN, stopSpraycan);
            private function startSpraycan(e:MouseEvent):void
                sprayCan = new Shape(); // nieuwe shape zodat die altyd vanboven ligt (in geval van vorige tekenen, ...)
                drawBoardmc.addChild(sprayCan); // shape toevoegen aan het 'board' movieclip
                sprayCan.graphics.moveTo(mouseX, mouseY); //verplaatst de tekenpositie naar de muis positie
                sprayCan.graphics.lineStyle(drawSize.width, activeColor); // zet de dikte van het penseel naar de lijndikte van de shapeSize movieclip
                drawBoardmc.addEventListener(MouseEvent.MOUSE_MOVE, drawSpraycan); // voegt een listener toe aan de volgende functie
            private function drawSpraycan(e:MouseEvent):void
                sprayCan.graphics.lineTo(mouseX,mouseY); //tekent een lijn van de huidige muis positie naar de verplaatste muispositie
            private function stopSpraycan(e:MouseEvent):void
                drawBoardmc.removeEventListener(MouseEvent.MOUSE_MOVE, drawSpraycan); //stopt het tekenen
            private function convertToBMD():void
                colorsBmd = new BitmapData(colors.width, colors.height);
                colorsBmd.draw(colors);
            public function chooseColor(e:MouseEvent):void
                pixelValue = colorsBmd.getPixel(colors.mouseX, colors.mouseY); //slaagt de geklikte RGB waarde op in de variabele pixelValue
                activeColor = pixelValue
            public function changeDrawSize(e:MouseEvent):void
                if (drawSize.width >=50)
                    drawSize.width = 1;
                    drawSize.height = 1;
                else
                    drawSize.width += 5;
                    drawSize.height = drawSize.width;
            public function setDrawBoard(board):void
                drawBoardmc = board;
            public function setButton(toolButton):void
                spraycan = toolButton;
            /*public function setActive(activeTool):void
                active = activeTool;
            public function setDrawSize(drawsize):void
                drawSize = drawsize;
            public function setColorsMC(colorsmc):void
                colors = colorsmc;
            public function setSizePanel(sizepanel):void
                sizePanel = sizepanel;
    [/AS]
    Eraser.as, class to erase
    [AS]
    package
        import flash.display.MovieClip;
        import flash.display.Shape;
        import flash.display.DisplayObject;
        import flash.display.BitmapData;
        import flash.events.MouseEvent;
        public class Eraser extends MovieClip
            private var eraser:Shape;
            private var drawBoardmc:MovieClip;
            private var eraserB:MovieClip;
            //private var active:String;
            private var drawSize:MovieClip;
            //private var spraycan:Spraycan;
            public function Eraser():void
            /*public function eventLists():void
                eraserB.addEventListener(MouseEvent.MOUSE_UP, eraserTool);
                eraserB.addEventListener(MouseEvent.MOUSE_OVER, function(){gotoAndStop(2);}) ;
                eraserB.addEventListener(MouseEvent.MOUSE_OUT, function(){gotoAndStop(1);});
            public function eraserTool(e:MouseEvent):void
                //actieve tool afsluiten
                Main.removeEvents();
                //eraserB.addEventListener(MouseEvent.MOUSE_UP, function(){gotoAndStop(2);});
                //listeners
                Main.addEvents(drawBoardmc, MouseEvent.MOUSE_DOWN, startEraser);
                Main.addEvents(drawBoardmc, MouseEvent.MOUSE_DOWN, stopEraser);
            private function startEraser(e:MouseEvent):void
                eraser = new Shape();
                drawBoardmc.addChild(eraser);
                eraser.graphics.moveTo(mouseX, mouseY);
                eraser.graphics.lineStyle(drawSize.width, 0x000000);
                drawBoardmc.addEventListener(MouseEvent.MOUSE_MOVE, drawEraser);
            private function drawEraser(e:MouseEvent):void
                //if (board.width > mouseX && board.height > mouseY) {
                eraser.graphics.lineTo(mouseX, mouseY);
            function stopEraser(e:MouseEvent):void
                drawBoardmc.removeEventListener(MouseEvent.MOUSE_MOVE, drawEraser);
            /*private function quitActiveTool():void
                switch (active)
                    case "Spraycan" :
                        drawBoardmc.removeEventListener(MouseEvent.MOUSE_DOWN, spraycan.startSpraycan);
                        drawBoardmc.removeEventListener(MouseEvent.MOUSE_UP, spraycan.stopSpraycan);
                    case "Eraser" :
                        drawBoardmc.removeEventListener(MouseEvent.MOUSE_DOWN, startEraser);
                        drawBoardmc.removeEventListener(MouseEvent.MOUSE_UP, stopEraser);
                    default:
            public function setDrawBoard(board):void
                drawBoardmc = board;
            public function setButton(toolButton):void
                eraserB = toolButton;
            /*public function setActive(activeTool):void
                active = activeTool;
            public function setDrawSize(drawsize):void
                drawSize = drawsize;
    [/AS]

Maybe you are looking for

  • ABAP development - Using Predefined Logical Path

    Hi, I need to save content of a table to a flat file which i am doing in my ABAP code  these files can be very large ,  What i want to know is chosing a folder location for these file i want to use predefined Logical path for this so that the ABAP co

  • Can I install adobe creative suite 5 master collection on windows 8

    can I install adobe creative suite 5 master collection on windows 8

  • Multiple CSV files into single Excel as multiple spreadsheets

    Hi Experts,   Can any one please help on the below requirement Requirement:    I have three .csv files for example (CSV_file1.csv, CSV_file2.csv, CSV_file3.csv,). I want to load these three different files into one Excel file as three different sprea

  • POWER ADAPTER HAS JUST CAUGHT FIRE!!!

    While sitting using my 15' powerbook g4 i noticed a strange burning smell. At closing the screen i realized what it was, the power adapter had caught fire at the part where the cable enters the brick. This could have been disastrous if i wasn't here

  • Change the Material type & Material industries

    Hi Expert,                   I have created one material code. Suppose that Material Code is " XYZ" Material code : "XYZ" Material Type : FERT Industry sector: Chemical industries I want to Change material type & Industry sector. Please help me how i