Welcome, Guest. Please login or register.
Did you miss your activation email?
05/22/12, 07:34
Home Help Search Login Register
News: Parsley Flex framework review featuring quiz application, in our Flex frameworks series
Flex SDK 4.5 mobile roadmap: begin with your mobile development
Swiz Flex framework review featuring quiz application
New homepage we release our new Homepage, take a look ...

+  Flash-db
|-+  General
| |-+  Flash MX 2004 (Moderators: Flash-db, Musicman, vesa kortelainen, Ronald Wernecke, Andresss, papachan)
| | |-+  * SOLVED * Help! Sooooo CLOSE! How do I call a Var in a function???
0 Members and 1 Guest are viewing this topic. « previous next »
Pages: [1] Print
Author Topic: * SOLVED * Help! Sooooo CLOSE! How do I call a Var in a function???  (Read 2044 times)
MrEd
Seasoned Programmer
***
Posts: 103



View Profile WWW Email
« on: 12/10/09, 02:41 »

I need to have the VAR 'MyMovie" be defined and used in an onEnterFrame within a function.

here is my code:

function MoveMovie(MyMovie:String,xEnd:Number,yEnd:Number){
   trace(MyMovie); <------ This works = Box
   DividedBy = 5;
   MyMovie.onEnterFrame = function(){ <-----This does not! Sad How do I call "MyMovie" in an onEnterFrame or the properties of MyMovie. example MyMovie._x?
   cpx = (xEnd - this._x) / DividedBy;
   cpy = (yEnd - this._y) / DividedBy;
   trace(this._x);
   trace(this._y);
   //cp = Math.round(cp);
   this._x += cpx;
   this._y += cpy;
   Rounded = Math.round(this._x);
   Rounded = Math.round(this._y);
   trace(Rounded);
   if(Rounded == xEnd or Rounded == yEnd) { delete this.onEnterFrame;}
   }
}

Box.onPress = function(){
MoveMovie("Box",777,198);
}

« Last Edit: 12/10/09, 03:17 by MrEd » Logged
MrEd
Seasoned Programmer
***
Posts: 103



View Profile WWW Email
« Reply #1 on: 12/10/09, 03:08 »

Found the same question here:
http://www.bigresource.com/FLASH-onEnterFrame-and-clip-container-vars-within-class-definitions-Flash8-kEZSz9NCZT.html

But no answer on that form. Sad
Logged
MrEd
Seasoned Programmer
***
Posts: 103



View Profile WWW Email
« Reply #2 on: 12/10/09, 03:17 »

FIGURED IT OUT!

function MoveMovie(MyMovie:MovieClip,xEnd:Number,yEnd:Number){ // changed from a string to MovieClip

   trace(MyMovie);
   DividedBy = 5;
   MyMovie.onEnterFrame = function(){
   cpx = (xEnd - this._x) / DividedBy;
   cpy = (yEnd - this._y) / DividedBy;
   trace(this._x);
   trace(this._y);
   //cp = Math.round(cp);
   this._x += cpx;
   this._y += cpy;
   Rounded = Math.round(this._x);
   Rounded = Math.round(this._y);
   trace(Rounded);
   if(Rounded == xEnd or Rounded == yEnd) { delete this.onEnterFrame;}
   }
}

Box.onPress = function(){
MoveMovie(this,25,33); YES!!!!! Smiley
}
Logged
Pages: [1] Print 
« previous next »
Jump to:  


Powered by MySQL Powered by PHP Powered by SMF 1.1.16 | SMF © 2011, Simple Machines Valid XHTML 1.0! Valid CSS!