A Flash Developer Resource Site

Results 1 to 4 of 4

Thread: Need to reference a movieClip via a variable.

  1. #1
    Member
    Join Date
    Jul 2005
    Location
    Calgary AB
    Posts
    54

    Need to reference a movieClip via a variable.

    The scene is a number of movie clips, all already added to the stage (i.e. not dynamically) and when one is clicked, I need to call a property of that clip.

    The clips are named frame_1, frame_2, etc.
    Doing this
    Actionscript Code:
    frame_1.zoomIn();
    works. Ideally, I would have used 'event.target.name.zoomIn()' but obviously that won't work. So I looked at variables...

    Code:
    public function galleryRoom()
    		{
    			this.addEventListener(MouseEvent.CLICK, lookAtFrame);
    
    		}
    		
    		public function lookAtFrame(event:MouseEvent):void
    		{
    			trace('Event = '+event.target.name);
    			
    			var Frames:Array = [];
    			var i:int =new int();
    			
    			for (i=0; i<3; i++)
    			{
    				var F:frame;
    				F.name = "frame_"+i;
    				Frames[i] = F;
    			}
    					
    			var FullName:String= String(event.target.name);
    			var nString:String = new String();
    			nString = FullName.substr(6,1);
    			
    			var n:Number = new Number(nString);
    				
    			//Frames[n].zoomIn();
    
    
    		}
    Gallery Room is the class of the big, all containing movieClip that gets loaded to the stage first.

    Any ideas?
    ~Nick

  2. #2
    Senior Member flamedude's Avatar
    Join Date
    Jun 2003
    Location
    Vancouver, BC
    Posts
    252
    var n:Number = new Number(nString);
    var newFrame:MovieClip = this["Frames"+n];
    newFrame.zoomIn();

    Would that work?

  3. #3
    Will moderate for beer
    Join Date
    Apr 2007
    Location
    Austin, TX
    Posts
    6,801
    Things are not their names.

    Just use
    Code:
    event.target.zoomIn();
    rather than
    Code:
    event.target.name.zoomIn()
    You cannot call zoomIn on the name, because the name is a String and does not have a zoomIn method. The target is the actual object. Or some child of it. If that's the case you'll need to play with mouseChildren properties so that you don't get interior objects instead of the objects you want as the targets. Or you could add your click listeners to all the objects you want and use currentTarget rather than target.

  4. #4
    Member
    Join Date
    Jul 2005
    Location
    Calgary AB
    Posts
    54
    Thanks Flamedude. Frames is an array, so I don't think it would. 'this' wouldn't refer to the same movie clip either. Or am I missing something?

    5Tons - thanks - that worked perfectly! As you can imagine, I'm now getting errors when clicking on something other than the movieclips. I'll play with currentTarget and see what happens - thanks for the tip.
    It's actually a wall with pictures on it that you can click on to zoom in.
    ~Nick

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center