Motion Function
Heya.
Let me try and re-word my problem: I want a function that'll move an instance of a movie clip up, down, left or right a precise distance. but NOT immediately, I'd like it to slide. That's my problem - I can make it move immediately, but I'd like that slidey motion.
Any idea?
FlashKit > Flash Help > Flash ActionScript
Posted on: 10-30-2002, 08:13 PM
View Complete Forum Thread with Replies
Sponsored Links:
Motion Function
What is wrong with this?
Code:
stop ();
motionFunction = function () {
var currentY = my_mc._y
var newY = _ymouse;
var speed = .1;
this.onEnterFrame = function() {
var dy = newY - currentY
currentY += dy*speed;
if (dy<=1) {
currentY = newY;
}
};
}
motionFunction.apply (my_mc)
When i skip the currentY and newY declarations, and enter their values straight into my .onEnterFrame function, the code works fine. I tried removing the variable's 'var's, to remove the variable's limited scope, but this made no difference.
Any ideas?
Thanks
View Replies !
View Related
Drag Function>motion
I'm trying to make an interactive book in flash.Motion is getting wright.At the moment when I push a button(pagecurl)the page unfolds.I would like this motion to be like a dragfunction.Frame 1 holds the button.Frame2 to 39 motion.So frame2 to 39 should be a drag function at frame 40 is a stop action with a new button.This one should make a drag from frame 40 to 1.Anyone can help me out with this scripting?Big thx in advance.
View Replies !
View Related
Drag Function>motion
At the moment I'm making a book in flash.When I go over the corner of a page I get a pagecurleffect.Hitting that button makes the pages turn to the next one.I would like this motion(turning to next page) to be like a drag function.you know like you are really turning the pages.At frame one is the button.frame2 to 40 holds the motion for turning the pages.
At frame 40 there is a new button on the left side to turn to previous page.So this should be a reverse action going from frame 40 to 1.Anyone can help me out with this drag function,drag function in reverse.
Btw you can see the effect I'm talking about on
www.perfectfools.com/
Big thx in advance!!!
View Replies !
View Related
Motion As A Math Function
Hello all.
I would like to change the position of an object as a function of time (or frame...) using script. I just did it using a spreadsheet for the numbers, and typing in positions for every frame, and it looked good, but was a little tedious.
If it helps, y should equal y0 + vt + 1/2gt^2 , where y0 is the starting position, v is a constant, t is the time, and g is also a constant, and t^2 is the time squared.
Any ideas would be appreciated.
BobR
View Replies !
View Related
Urgent- Calling A Function For My Motion
As I type this, I'm straining to see the screen through my bloodshot eyes. I have Honestly been trying to wire this file for 18 hours straight! Please, Somebody, anybody...help me understand what the *!@# is wrong with me!
I just want to make a scripted motion function, I realize that it's tough to know what's happening in someone elses code looking in cold, but at this point, I'm desperate.
If you can see something that I might be doing wrong, I'll be very grateful and willing to provide some sort of retributive generousity
Source files available to whomever might be of service.
Thank you in advance,
Mac Baker
here is my function:
Code:
function construct(clipName, whereToGo,WhereAmI) {
clipMover = ("_root."+clipName+"Move");
clipPos = ("_root."+clipName+"Pos");
clipPosX = ("_root."+clipName+"PosX");
clipPosY = ("_root."+clipName+"PosY");
clipGoX = ("_root."+clipName+"GoX");
clipGoY = ("_root."+clipName+"GoY");
clipScaleitX = ("_root."+clipName+"ScaleitX");
clipScaleitY = ("_root."+clipName+"ScaleitY");
clipSpeed = ("_root."+clipName+"Speed");
_root.secGoto = whereToGo;
whereAmI = WhereAmI;
clipY= eval(WhereAmI +"._y");
clipX= eval(WhereAmI +"._x");
// CONSTRUCT TO THE INTRO VIDEO
// if the makeFade variable has been set, and it's not in motion, construct to the logoeo page
if (clipMover=true && root.secGoto == "intro") {
trace(clipMover);
//disable Buttons
_root.currSec = "inTransition";
// start the movement
_y = _root.decel(_y, clipGoY, clipSpeed);
_x = _root.decel(_x, clipGoX, clipSpeed);
// Call the fade method
c.fade(_root.sectionClicked, 5);
if ((Math.round(clipY) == clipGoY) && (Math.round(clipX) == clipGoX) && (clipPos == 8)) {
clipMove = false;
_root.currSec = "page";
_root.secGoto = "intro";
clipPos = 7;
} else if ((Math.round(clipY) == clipGoY) && (Math.round(X) == clipGoX)) {
clipGoY = clipPosY[clipPos];
clipGoX = clipPosX[clipPos];
clipScaleitY = clipPosY[clipPos];
clipScaleitX = clipPosX[clipPos];
clipPos++;
}
}
}
here is my mcAction:
Code:
onClipEvent (enterFrame) {
startDrag(this);
_root.construct("mainBar","page", targetPath(this));
}onClipEvent (enterFrame) {
View Replies !
View Related
Random Motion With Stop Function..?
ok i have tried out suprabeers random tutorial.THX!
and my problem is that i want to stop those little flying buttons with an rollover and then a small menu shall appear where you can choose links or sth.
but i've tried a lot and it doesnt worked.
can ypu plz help me?
and i am a noob so be nice :-)
View Replies !
View Related
To All Flash Gurus: MX RP Motion Function. Help: How To Apply This? Thanks
Hi,
i just found out this code for motion function based on Robert Penner's easing equations. I am a little bit lost in how to use it and aply it to a MC. A few days ago i created a function which fades in and fades out a MC and just insert this code in the timeline on an actions layer:
MC.fade("in", speed, limit);
How can i apply this functions to a MC? Here is the code:
// Easing a MovieClip from one position to target position within time/frame.
// Based on Robert Penner's easing equations.
MovieClip.prototype.initEase = function(dur,newx,newy,oldx,oldy){
this.dur = dur;
this.easeType = [ // for convenience
'linearTween', // 0
'easeinquad' , // 1
'easeoutquad', // 2
'easeinoutquad', // 3
'easeinsine', // 4
'easeoutsine', // 5
'easeinoutsine', // 6
'easeinexpo', // 7
'easeoutexpo', // 8
'easeinoutexpo', // 9
'easeincirc', // 10
'easeoutcirc', // 11
'easeinoutcirc' // 12
];
this.newX = newx;
this.newY = newy;
this.oldX = oldx;
this.oldY = oldy;
this.t = 0;
}
MovieClip.prototype.ease = function(easeTypeX,easeTypeY){
this.t++;
if (this.t<=this.dur) {
// if only one type wanted 4 x & y, only x need b given
if(easeTypeY==null){
easeTypeY = easeTypeX;
}
// if easeType isNumber convert to string
// ease('easeInOutCirc',11) will not work. stick to one type.
if(typeof easeTypeX == "number") {
easeTypeX = this.easeType[easeTypeX];
easeTypeY = this.easeType[easeTypeY];
}
// ease flic on!!
this._x = this[easeTypeX](this.t, this.oldx, this.newx, this.dur);
this._y = this[easeTypeY](this.t, this.oldy, this.newy, this.dur);
}
}
////////////// SIMPLE LINEAR TWEENING //////////////////
// t: current time, b: beginning value, c: change in value, d: duration
MovieClip.prototype.linearTween = function (t, b, c, d) {
return c*t/d+b;
};
///////////// QUADRATIC EASING ///////////////////
// quadratic easing in - accelerating from zero velocity
// t: current time, b: beginning value, c: change in value, d: duration
// t and d can be frames or seconds/milliseconds
MovieClip.prototype.easeInQuad = function (t, b, c, d) {
return c*t*t/(d*d)+b;
};
// quadratic easing out - decelerating to zero velocity
MovieClip.prototype.easeOutQuad = function (t, b, c, d) {
return -c*t*t/(d*d)+2*c*t/d+b;
};
// quadratic easing in/out - acceleration until halfway, then deceleration
MovieClip.prototype.easeInOutQuad = function (t, b, c, d) {
if (t<d/2) {
return 2*c*t*t/(d*d)+b;
}
var ts = t-d/2;
return -2*c*ts*ts/(d*d)+2*c*ts/d+c/2+b;
};
///////////// EXPONENTIAL EASING /////////////////
// exponential easing in - accelerating from zero velocity
MovieClip.prototype.easeInExpo = function (t, b, c, d) {
var flip = 1;
if (c<0) {
flip *= -1;
c *= -1;
}
return flip*(Math.exp(Math.log(c)/d*t))+b;
};
// exponential easing out - decelerating to zero velocity
MovieClip.prototype.easeOutExpo = function (t, b, c, d) {
var flip = 1;
if (c<0) {
flip *= -1;
c *= -1;
}
return flip*(-Math.exp(-Math.log(c)/d*(t-d))+c+1)+b;
};
// exponential easing in/out - accelerating until halfway, then decelerating
MovieClip.prototype.easeInOutExpo = function (t, b, c, d) {
var flip = 1;
if (c<0) {
flip *= -1;c *= -1;
}
if (t<d/2) {
return flip*(Math.exp(Math.log(c/2)/(d/2)*t))+b;
}
return flip*(-Math.exp(-2*Math.log(c/2)/d*(t-d))+c+1)+b;
};
///////////// SINUSOIDAL EASING //////////////////
// sinusoidal easing in - accelerating from zero velocity
MovieClip.prototype.easeInSine = function (t, b, c, d) {
return -c*Math.cos(t/d*Math.PI/2)+c+b;
};
// sinusoidal easing out - decelerating to zero velocity
MovieClip.prototype.easeOutSine = function (t, b, c, d) {
return c*Math.sin(t/d*Math.PI/2)+b;};
// sinusoidal easing in/out - accelerating until halfway, then decelerating
MovieClip.prototype.easeInOutSine = function (t, b, c, d) {
return -c/2*(Math.cos(Math.PI*t/d)-1)+b;
};
///////////// CIRCULAR EASING ///////////////////
// circular easing in - accelerating from zero velocity
MovieClip.prototype.easeInCirc = function (t, b, c, d) {
return -c*(Math.sqrt(1-t*t/(d*d))-1)+b;
};
// circular easing out - decelerating to zero velocity
MovieClip.prototype.easeOutCirc = function (t, b, c, d) {
return c*Math.sqrt(1-(t-d)*(t-d)/(d*d))+b;
};
// circular easing in/out - acceleration until halfway, then deceleration
MovieClip.prototype.easeInOutCirc = function (t, b, c, d) {
if (t<d/2) {
return -c/2*(Math.sqrt(1-4*t*t/(d*d))-1)+b;
}
return c/2*(Math.sqrt(1-4*(t-d)*(t-d)/(d*d))+1)+b;
};
Thanks,
Miguel
View Replies !
View Related
To All Flash Gurus: MX RP Motion Function. Help: How To Apply This? Thanks
Hi,
i just found out this code for motion function based on Robert Penner's easing equations. I am a little bit lost in how to use it and aply it to a MC. A few days ago i created a function which fades in and fades out a MC and just insert this code in the timeline on an actions layer:
MC.fade("in", speed, limit);
How can i apply this functions to a MC? Here is the code:
// Easing a MovieClip from one position to target position within time/frame.
// Based on Robert Penner's easing equations.
MovieClip.prototype.initEase = function(dur,newx,newy,oldx,oldy){
this.dur = dur;
this.easeType = [ // for convenience
'linearTween', // 0
'easeinquad' , // 1
'easeoutquad', // 2
'easeinoutquad', // 3
'easeinsine', // 4
'easeoutsine', // 5
'easeinoutsine', // 6
'easeinexpo', // 7
'easeoutexpo', // 8
'easeinoutexpo', // 9
'easeincirc', // 10
'easeoutcirc', // 11
'easeinoutcirc' // 12
];
this.newX = newx;
this.newY = newy;
this.oldX = oldx;
this.oldY = oldy;
this.t = 0;
}
MovieClip.prototype.ease = function(easeTypeX,easeTypeY){
this.t++;
if (this.t<=this.dur) {
// if only one type wanted 4 x & y, only x need b given
if(easeTypeY==null){
easeTypeY = easeTypeX;
}
// if easeType isNumber convert to string
// ease('easeInOutCirc',11) will not work. stick to one type.
if(typeof easeTypeX == "number") {
easeTypeX = this.easeType[easeTypeX];
easeTypeY = this.easeType[easeTypeY];
}
// ease flic on!!
this._x = this[easeTypeX](this.t, this.oldx, this.newx, this.dur);
this._y = this[easeTypeY](this.t, this.oldy, this.newy, this.dur);
}
}
////////////// SIMPLE LINEAR TWEENING //////////////////
// t: current time, b: beginning value, c: change in value, d: duration
MovieClip.prototype.linearTween = function (t, b, c, d) {
return c*t/d+b;
};
///////////// QUADRATIC EASING ///////////////////
// quadratic easing in - accelerating from zero velocity
// t: current time, b: beginning value, c: change in value, d: duration
// t and d can be frames or seconds/milliseconds
MovieClip.prototype.easeInQuad = function (t, b, c, d) {
return c*t*t/(d*d)+b;
};
// quadratic easing out - decelerating to zero velocity
MovieClip.prototype.easeOutQuad = function (t, b, c, d) {
return -c*t*t/(d*d)+2*c*t/d+b;
};
// quadratic easing in/out - acceleration until halfway, then deceleration
MovieClip.prototype.easeInOutQuad = function (t, b, c, d) {
if (t<d/2) {
return 2*c*t*t/(d*d)+b;
}
var ts = t-d/2;
return -2*c*ts*ts/(d*d)+2*c*ts/d+c/2+b;
};
///////////// EXPONENTIAL EASING /////////////////
// exponential easing in - accelerating from zero velocity
MovieClip.prototype.easeInExpo = function (t, b, c, d) {
var flip = 1;
if (c<0) {
flip *= -1;
c *= -1;
}
return flip*(Math.exp(Math.log(c)/d*t))+b;
};
// exponential easing out - decelerating to zero velocity
MovieClip.prototype.easeOutExpo = function (t, b, c, d) {
var flip = 1;
if (c<0) {
flip *= -1;
c *= -1;
}
return flip*(-Math.exp(-Math.log(c)/d*(t-d))+c+1)+b;
};
// exponential easing in/out - accelerating until halfway, then decelerating
MovieClip.prototype.easeInOutExpo = function (t, b, c, d) {
var flip = 1;
if (c<0) {
flip *= -1;c *= -1;
}
if (t<d/2) {
return flip*(Math.exp(Math.log(c/2)/(d/2)*t))+b;
}
return flip*(-Math.exp(-2*Math.log(c/2)/d*(t-d))+c+1)+b;
};
///////////// SINUSOIDAL EASING //////////////////
// sinusoidal easing in - accelerating from zero velocity
MovieClip.prototype.easeInSine = function (t, b, c, d) {
return -c*Math.cos(t/d*Math.PI/2)+c+b;
};
// sinusoidal easing out - decelerating to zero velocity
MovieClip.prototype.easeOutSine = function (t, b, c, d) {
return c*Math.sin(t/d*Math.PI/2)+b;};
// sinusoidal easing in/out - accelerating until halfway, then decelerating
MovieClip.prototype.easeInOutSine = function (t, b, c, d) {
return -c/2*(Math.cos(Math.PI*t/d)-1)+b;
};
///////////// CIRCULAR EASING ///////////////////
// circular easing in - accelerating from zero velocity
MovieClip.prototype.easeInCirc = function (t, b, c, d) {
return -c*(Math.sqrt(1-t*t/(d*d))-1)+b;
};
// circular easing out - decelerating to zero velocity
MovieClip.prototype.easeOutCirc = function (t, b, c, d) {
return c*Math.sqrt(1-(t-d)*(t-d)/(d*d))+b;
};
// circular easing in/out - acceleration until halfway, then deceleration
MovieClip.prototype.easeInOutCirc = function (t, b, c, d) {
if (t<d/2) {
return -c/2*(Math.sqrt(1-4*t*t/(d*d))-1)+b;
}
return c/2*(Math.sqrt(1-4*(t-d)*(t-d)/(d*d))+1)+b;
};
Thanks,
Miguel
View Replies !
View Related
Getting This Penner Motion/easing Function To Work
Hello,
I am attempting to get a MC to move/ease from down to up with the help of AS without resorting to tweens...
Mind you, I am still working with Flash5.
Right, I found this Robbert Penner function:
ActionScript:
onClipEvent(load)
{
Math.easeInElastic = function (t, b, c, d, a, p) {
if (t==0) return b; if ((t/=d)==1) return b+c; if (!p) p=d*.3;
if (a < Math.abs ) { a=c; var s=p/4; }
else var s = p/(2*Math.PI) * Math.asin (c/a);
return -(a*Math.pow(2,10*(t-=1)) * Math.sin( (t*d-s)*(2*Math.PI)/p )) + b;
};
}
I placed it on a MC (a different one from the ones mentioned below) on frame 1 on _root
With it I want to make a MC (lets call this MC Bob) move from down to up (out of sight) after the timeline in another MC (hostMC) has reached a certain Frame (lets say frame 23).
Since I have to tell Flash to execute this function (which I am forced by Flash5 to put functions within a ActionScript:
onClipEvent(load){
}
I put ActionScript:
onClipEvent(load){
_root.bob.Math.easeInElastic;
}
attached to another MC which I placed inside hostMC on frame 23.
Needless to say, it doesnt work.
But what am I doing wrong?
View Replies !
View Related
Expert Help Needed - Motion Function With Dynamic Parameters
I must admit that i am slightly out of my depth when it comes to functions with dynamic parameters and cycle statements, but i have produced a script that i feel i am so close to cracking (and need to before thursday!).
I have a groundfloor plan (gf_mc), within which is many departments (dep_1, dep_2 etc). Upon rolling on each department, the department rises slightly in scale, whilst a roll out causes them to retract to normal. When the department is released, the x and y scales of the gf_mc increase, whilst the x and y co-ordinates alter, so that the screen has effectively zoomed in on the department. When a department is in focus, all others reduce in alpha to make them near transparent.
Code:
function motionTween (target, newX, newY, newXscale, newYscale, newAlpha) {
currentX = target._x
currentY = target._y
currentXscale = target._xscale
currentXscale = target._yscale
currentAlpha = target._alpha
speed = .1;
if (newX = undefined) {
newX = currentX
}
if (newY = undefined) {
newY = currentY
}
if (newXscale = undefined) {
newXscale = currentXscale
}
if (newYscale = undefined) {
newYscale = currentYscale
}
if (newAlpha = undefined) {
newAlpha = currentAlpha
}
this.onEnterFrame = function() {
var dx = newX - currentX;
var dy = newY - currentY;
var dxs = newXscale - currentXscale
var dys = newYscale - currentYscale
var da = newAlpha - currentAlpha
if ((dx < 1) && (dy < 1) && (dxs < 1) && (dys < 1) && (da < 1)) {
currentX = newX
currentY = newY
currentXscale = newXscale
currentYscale = newXscale
currentAlpha = newAlpha
delete this.onEnterFrame;
} else {
currentX += dx*speed;
currentY += dy*speed;
currentXscale += dxs*speed;
currentYscale += dys*speed;
currentAlpha += da*speed;
}
}
}
//groundfloor department array
gf_ar = new Array ()
gf_ar[1] = gf_mc.dep_1 //department 1
gf_ar[2] = gf_mc.dep_2 //department 2
gf_ar[3] = gf_mc.dep_3 //department 3
gf_ar[4] = gf_mc.dep_4 //department 4
// etc...
for (i=1; i<= gf_ar.length; i++) {
var iDep = _root.gf_mc["dep_"+i]
iDep.onRollover = function () {
this.motionTween (this, undefined, undefined, 120, 120, 90)
}
iDep.onRollout = function () {
this.motionTween (this, undefined, undefined, 100, 100, 60)
}
// on release of gf_mc.dep_?, this department is the focused department & perform the function with its set parameters
iDep.onRelease = function () {
this = focusdep
this.motionTween (gf_mc, this.newX, this.newY, this.newXscale, this.newYscale, 70)
}
}
//department perameters
with (_root.gf_mc.dep_1) {
newX = 16
newY = 690
newXscale = 350
newYscale = 350
}
with (_root.gf_mc.dep_2) {
newX = -620
newY = -796
newXscale = 432
newYscale = 432
}
with (_root.gf_mc.dep_3) {
newX = -70
newY = -520
newXscale = 365
newYscale = 365
}
with (_root.gf_mc.dep_4) {
newX = -455
newY = -335
newXscale = 315
newYscale = 315
}
Primarily, the problem is that the motion functions are not performed. I cannot figure out why.
Additionally, i have a few extra questions:
1. In the function Itself, i have nabbed the coding:
Code:
this.onEnterFrame = function () {
What is 'this' in this instance?
similarly, later i used
Code:
delete this.onEnterFrame;
am i right in thinking that that peice of coding is re-usable, and that it is not permanently deleted, only telling the motion function to stop?
2. Whenever i trace the focusdep, it is always undefined. So although the output bar updates when i release a department, it only displays 'undefined' again.
Code:
iDep.onRelease = function () {
this = focusdep
this.motionTween (gf_mc, this.newX, this.newY, this.newXscale, this.newYscale, 70)
}
trace(focusdep)
3. Finally, i have made an attempt at causing the unfocused (not zoomed in on) departments to fade when another department is selected.
Code:
iDep.onRelease = function () {
this = focusdep
this.motionTween (gf_mc, this.newX, this.newY, this.newXscale, this.newYscale, 70)
if ((iDep != focusDep) && (focusDep != undefined) {
this.motionTween (this, undefined, undefined, undefined, undefined, 40)
}
I have a feeling this is horribly inaccurate. I am trying to say:
"if gf_mc.dep_? is not the focused department and the focused department is not undefined, fade gf_mc.dep_? to 40 alpha"
Thank you for any help!
View Replies !
View Related
Motion Tween Doesn't Work Inside Function
I made a motion tween that works great on it's own, but won't tween at all inside of a frame. Why not?
Here is the code as a function. What's up?:
Code:
import mx.transitions.Tween;
import mx.transitions.easing.*;
fadeIn(myMC);
fadeIn = function(mc) {
var myHoriTween:Tween = new Tween (mc,"_x",Back.easeOut,900,0,1.1,true);
}
View Replies !
View Related
Motion Tween Doesn't Work Inside Function
I made a motion tween that works great on it's own, but won't tween at all inside of a frame. Why not?
Here is the code as a function. What's up?:
Code:
import mx.transitions.Tween;
import mx.transitions.easing.*;
fadeIn(myMC);
fadeIn = function(mc) {
var myHoriTween:Tween = new Tween (mc,"_x",Back.easeOut,900,0,1.1,true);
}
View Replies !
View Related
Is It Possible? Motion Guide + Motion Tween + Actionscript Api Drawing
Hi
Im looking for some help I've done a lot of research and spent hours trying to find a way to do this so any input is appreciated.
I have drawn a shape in actionscript
_root.createEmptyMovieClip("myMoon",6);
with (myMoon){
beginFill(0x999999, 100);
drawCircle(50,120,30);
endFill();
}
new Tween(myMoon, "_x", Elastic.easeOut, 0, 300, 3, true);
Basically I have a tween on it that works fine but what I need to do is motion tween along a motion guide.
Of course I know how to achieve this through the normal way of drawing a circle through the tools box but I have to figure a way out to do this to the shape drawn in action script via the drawing api. How can I do this?
I presume I have to someway make this shape appear in my library as a symbol possibly? Hope someone has a soloution thanks a lot
View Replies !
View Related
No More Choppy Motion I Want To Learn Motion Using Actionscript
Hi, my experience is with motion tweens from point A to point B, clean and simple but notice the animation is VERY choppy on slower computers... I want to learn how to alpha, move from point a to point b with actionscript rather than simple motion tweens so the animation is SMOOTHER.... any resources I should check out? Books? Tut's to search for (I haven't had much luck searching).
Here's a sample of my Flash work using simple motion tweening:
http://www.workplaceinnovationsllc.com/flash.htm
Works great on a powerful computer but not on older slower machines..... you'll see where better scripting could make this site better, smoother.
Thanks!
Help!
View Replies !
View Related
[as3] Motion Guides And Motion Code
Adobe's touting Flash CS3's "Copy Motion as AS3" feature as a bridge between designers and developers. For the most part, I bet they're right. And there are probably other applications for the Animator class that we can't forsee at this time.
But I thought this feature's greatest use would be representing complex animation elegantly in a programmatic way. Simple animation can just be coded; it's the tough stuff that we'd prefer to animate in the Timeline, then convert to code. And Adobe seems to agree; their demonstration for this feature uses a motion tween that uses a motion guide, which is translated into Motion XML. But if you look closely at the XML, it doesn't describe motion at all: when you copy motion along a path as AS3 code, it'll first convert the entire tween to keyframes. That means, if you want to make the XML animation twice as long, you'll need to properly adjust the keyframe positions for each frame that was in the animation. That doesn't cut it for me.
On the other hand, if you just copy and paste the motion to another object, the guide will also be copied. This makes more sense; the Animator should be able to rely on a motion guide just as the Timeline seems to do.
Go ahead and give it a try. Make a little motion tween that uses a guide, copy and paste it as AS3, and look at the XML. Isn't it impractical?
View Replies !
View Related
Motion Tween (fade) Text Converted To Symbol No "motion"
I am using flash mx and my file includes text that is supposed to fade in and out.
I do exactly as I do with images - alpha 0 fades into 100 % etc, and it looks fine on the stage, but when I publish the text simply pops on and off with no recognition of the alpha channel fading in and out.
I create the text as static text - old english font - and then I convert it to a symbol. I tween the symbol from 0 to 100 alpha and back again. Presumably making it a symbol essentially makes it an image, right? no?
I am relatively new to flash so I may be missing something obvious?
(yes I have checked out places like flashkit.com, but not exactly what I am looking for, want more control.)
View Replies !
View Related
Function In A Function In A Function, A Scope Problem
Is this basic or what.. I have a nested functions, and I'm having a hell of a time getting all my variable through.
ActionScript Code:
var canyouseemee;
public function move()
{
for(var i:Number = 0; i < blah; i++)
{
zing, and then zang
if (zing==0)
{
guts
}
if (zang ==0)
{
something else
}
}
}
Now, I had always thought that since var canyouseemee is declared at the topmost layer, that I'd be able to see it from anywhere below it. Well, it turns out that I can only see it from within the move()function, and not anything below it. is this normal? I thought you couldn't see a local variable of a lower (deeper) function, but could see higher (shallower) variables...
View Replies !
View Related
Call A Function In A Duplicated Movie Clip Form Another Function : (
i have a movie clip on my root name "pl".
on command, it duplicates with instance name as "y0","y1", etc.
here is the method :
function callPL(transmit,receive,addy,level) {
var newName = "y"+_root.x;
duplicateMovieClip("_root.pl",newName,101);
_root[newName]._x = 400;
_root[newName]._y = 400;
_root.[newName].start(transmit,receive,addy,level); //look here
}
there i attempt to call a function of the newly duplicated clip call "start()".
Start() function is written on the first frame of the movieclip like this :
function start(a,b,address,level) {
a.sendAndLoad(address,b,"Post");
this.path = b;
b.onLoad=function(success) {
gotoAndPlay("start");
}
}
however it seems like the function callPL() could not invoke function start() of the new movieClip.I have no idea how is it so.
Even when i trigger it with a onLoad handler it still doesnt work
pls shed some light.
View Replies !
View Related
Calling Constructor In Condition: A Function Call On A Non-function Was Attempted.
Hi guys,
Please help me somebody with this cos I have really no idea. I have made a simply condition calling a constructor of a class. Today I had to add an "else if", what caused the compilator to show me "A function call on a non-function was attempted."...
ActionScript Code:
function loadIt() { if (var1 == "1") { var a:SomeClass = new SomeClass(true); } else if(var2 == "1"){ var a:SomeClass = new SomeClass(false); //<- if this is not here, everything works fine } else { var b:SomeOtherClass = new SomeOtherClass(); b.init(); }}
Any ideas? Thanks for any help!
Poco
View Replies !
View Related
Filling Function Arguments With Array Items, Function.call()
HI!
I have this code but I cannot work out how to fill in function parameters based on an array and it's length, see line 7
ActionScript Code:
import com.robertpenner.easing.Cubic;MovieClip.prototype.framesTimeout = function(func:Function, frames:Number, args:Array) { var t:Number = 0; var mc:MovieClip = this.createEmptyMovieClip(String(new Date().getTime()), this.getNextHighestDepth()); mc.onEnterFrame = function() { if (t == frames) { func.call(this._parent,args); delete this.onEnterFrame; this.removeMovieClip(); } else { t++; } };};MovieClip.prototype.movex = function(x:Number, frames:Number) { trace(x+" "+frames) delete this.movex.onEnterFrame; this.movex.removeMovieClip(); if (!frames) { frames = 20; } var t:Number = 0; var sx:Number = this._x; var ax:Number = x-this._x; var mc:MovieClip = this.createEmptyMovieClip("movex", this.getNextHighestDepth()); mc.onEnterFrame = function() { if (t == frames) { delete this.onEnterFrame; this.removeMovieClip(); } else { t++; this._parent._x = Cubic.easeOut(t, sx, ax, frames); } };};MovieClip.prototype.otherfunction = function(param1, param2, param3, param4){ trace(param1+" "+param2+" "+param3+" "+param4)}mc.framesTimeout(movex, 50, [100, 50]) mc.framesTimeout(otherfunction, 200, ["asd", 1, 2, 55])
Is it possible to call a function and fill in the parameters based on an array and it's lenth?
View Replies !
View Related
My Function Isn't Functioning/Actionscript To Call A Function Flash MX 2004
Hello,
Well in theory I know how to create a function but for some reason I am unable to call it.
Can someone take a look at it and tell me what went wrong. Basically when I go to "a certain page" I want to click on a button and have it go to another page known as "pics" it then will load a jpeg there known as jpeg loader. Now I know it works properly without a functin, but because I am lazy I do not want to write more code than I have to, there are like 300 differnt jpegs I have to load. Thus I need to create a function.
here is my AS
ActionScript Code:
//this is on frame one of my root timeline
//I am trying to call the function "display" on release of my button
omnihotelButton.onRelease = display ("J010 Omni Hotel.jpg");
//this is my function that I set up it is also on my root, but on a different frame
//this function is named display and it goes to the "pics" page and stops
where it then loads a jpeg which is et up as my variable.
//the xscale and the yscale are just setting up my size of the jpeg.
function display(jpeg){
_root.gotoAndStop("pics");
jpegLoad_mc.loadMovie(jpeg);
jpegLoad_mc._xscale=90;
jpegLoad_mc._yscale=90;
}
View Replies !
View Related
Function Calling From The _root But Call A Function Within A Instance
I have created a new instance 'Check_1' to work as a checkbox with a set of propertys and functions.
All ive done is created the functions in a script in the first frame of the instance-movie these are...
Simple......
================================================== =======
selected = -1;
function select_frame (FrameNum) {
gotoAndPlay (FrameNum);
}
function change_select () {
select_frame(2);
trace (selected);
}
function change_unselect () {
select_frame(1);
selected = -1;
}
================================================== =======
now from the _root i wish to call the above functions to change the instance propertys, it all works fine from within the instance but i also need to use the functions for that instance from the _root...
iv'e tried the follow with no joy...
_level0.Check_1.change_select()
Any light would be greatly appreciated.
View Replies !
View Related
Parsing Data To A Function And Altering It Inside The Function
Hi all
I need to parse variables to a function and let the values of the variables be changed inside the function. But in a way that the data are actually changed, not only a reference to the data! It is not possible using primitive data but should be possible with composite data.
But I cant get it right - any suggestions?
code:
test = new Object();
test = false;
aFunction = function(control){
control = true;
trace(test);
other code here...
}
How can I make the trace(test) output true when I call the aFunction(test) with test as parameter?
Hope anyone have the answer!
Ciao ciao
T
View Replies !
View Related
Define The OnMouseDown Function To Point To A Member Function
Hi,
I have a class called CField that contains a MovieClip. And I like to be able to call a member function inside my class, when the mouse click on the MovieClip. If I use the callback function onMouseDown = function() from inside the class, the function is overwritten by the last created instance of the class (see the the Main Program). How do I define the onMouseDown function to point to a member function?
// Main Program
.
// Create and draw 10 fields
for (i=0;i<10;i++)
{
var field:CField = new CField(i*50, 50);
field.Draw(i);
}
.
My class is looking more or less like this:
// Field Class
class CField
{
// Properties
var m_nPosX:Number;
var m_nPosY:Number;
var m_mcField;
// Constructor
function CField(nPosX:Number, nPosY:Number)
{
this.m_nPosX = nPosX;
this.m_nPosY = nPosY;
}
public function Draw(nCount:Number)
{
var sInstance:String = new String(nCount.toString(10));
this.m_mcField = _root.createEmptyMovieClip (sInstance, nCount);
with (this.m_mcField)
{
_x = this.m_nPosX;
_y = this.m_nPosY;
loadMovie("Field.swf", nCount);
onMouseDown = function ()
{
trace("Mouse Clicked");
}
}
}
}
View Replies !
View Related
Inside XmlOnload Function Can Not Call Other Function Directly
I have a question, why the test function can not be called ?
Thanks.
Code:
class testClass {
public function testClass() {
var XMLData:XML = new XML();
XMLData.load("coonfig.xml");
XMLData.onLoad = this.xmlOnLoad;
}
public function xmlOnLoad(success:Boolean) {
if (success) {
// this.test();
test();
}
}
public function test () {
trace("test success");
}
}
View Replies !
View Related
Actionscript Function Similar To PHPs Explode Function?
Hello everyone, first off, I'd like to say hi to everyone as this is my first post and I have joined very recently! So yeah, I'm glad to be here and yeah, hope I find what I need.
Right, well for those of you who know PHP there is a function known as explode(), which basically splits a string apart by a certain character and throws it into an array.
For example, in PHP.
PHP Code:
$string = "lol,text,omfg,wow,hi";
I can explode that string by the , character and it would split up everything and throw each little "section" into an array.
PHP Code:
$bits = explode( ',', $string );
I can now access access the bits by $bits[0], $bits[1], $bits[2], $bits[3], and $bits[4].
Now, is there anyway you can do this in Actionscript? Say I have a string in actionscript and I've datatyped it to a string.
PHP Code:
var myString:String = "text1|text2|text3|text4";
How can I explode, or break apart, the string by the | character and get the "text1", "text2", etc, strings?
View Replies !
View Related
Mysql->PHP->FLASH Function. (Passing Function To A Package)
I've just started with ActionScript3.0, and is currently working on a flash that is to communicate with a mysql database and have found a great deal of example code online that I've started to work with.
Currently I have the following package added to my project:
Code:
package
{
import flash.events.*;
import flash.net.*;
public class SendAndLoad
{
public function SendAndLoad()
{}
public function sendData( url:String, _vars:URLVariables, completeFunc:Function ):void
{
var request:URLRequest = new URLRequest( url );
var loader:URLLoader = new URLLoader();
loader.dataFormat = URLLoaderDataFormat.VARIABLES;
request.data = _vars;
request.method = URLRequestMethod.POST;
loader.addEventListener( Event.COMPLETE, completeFunc );
loader.addEventListener( IOErrorEvent.IO_ERROR, onIOError );
loader.load(request);
}
//private function handleComplete( event:Event ):void
//{
// var loader:URLLoader = URLLoader( event.target );
// trace( "Par: " + loader.data.par );
// trace( "Message: " + loader.data.msg );
//}
private function onIOError(event:IOErrorEvent):void
{
trace("Error loading URL.");
}
}
}
And is running the following code in my flash:
Code:
import SendAndLoad;
import flash.net.URLVariables;
function loadUsername( event:Event ):void
{
var loader:URLLoader = URLLoader( event.target );
//userNameText.text = "ffff";
userNameText.text = loader.data.user;
}
var url:String = "pages/test.php";
var vars:URLVariables = new URLVariables();
var sal:SendAndLoad = new SendAndLoad();
sal.sendData( url, vars, loadUsername );
As you can see I am trying to seperate the function to be called when the return value of the page I am accessing returns with a value, so I wont need to pass all different actions to be called on different pages I will be requesting throughout my flash program.
But as it is now, the function loadUsername, never even gets called, which I assume is because the package can't call the function outside it.
As I said, I am just starting out with ActionScript 3.0, and is kind of stuck at this.
Any thoughts?
View Replies !
View Related
Mysql->PHP->FLASH Function. (Passing Function To A Package)
I've just started with ActionScript3.0, and is currently working on a flash that is to communicate with a mysql database and have found a great deal of example code online that I've started to work with.
Currently I have the following package added to my project:
Code:
package
{
import flash.events.*;
import flash.net.*;
public class SendAndLoad
{
public function SendAndLoad()
{}
public function sendData( url:String, _vars:URLVariables, completeFunc:Function ):void
{
var request:URLRequest = new URLRequest( url );
var loader:URLLoader = new URLLoader();
loader.dataFormat = URLLoaderDataFormat.VARIABLES;
request.data = _vars;
request.method = URLRequestMethod.POST;
loader.addEventListener( Event.COMPLETE, completeFunc );
loader.addEventListener( IOErrorEvent.IO_ERROR, onIOError );
loader.load(request);
}
//private function handleComplete( event:Event ):void
//{
// var loader:URLLoader = URLLoader( event.target );
// trace( "Par: " + loader.data.par );
// trace( "Message: " + loader.data.msg );
//}
private function onIOError(event:IOErrorEvent):void
{
trace("Error loading URL.");
}
}
}
And is running the following code in my flash:
Code:
import SendAndLoad;
import flash.net.URLVariables;
function loadUsername( event:Event ):void
{
var loader:URLLoader = URLLoader( event.target );
//userNameText.text = "ffff";
userNameText.text = loader.data.user;
}
var url:String = "pages/test.php";
var vars:URLVariables = new URLVariables();
var sal:SendAndLoad = new SendAndLoad();
sal.sendData( url, vars, loadUsername );
As you can see I am trying to seperate the function to be called when the return value of the page I am accessing returns with a value, so I wont need to pass all different actions to be called on different pages I will be requesting throughout my flash program.
But as it is now, the function loadUsername, never even gets called, which I assume is because the package can't call the function outside it.
As I said, I am just starting out with ActionScript 3.0, and is kind of stuck at this.
Any thoughts?
View Replies !
View Related
Functions Inside A Function Returning To Previous Function
This is a kind of long post so for your benifit here's some story Tags, if you don't want to read my sobbing story, then just look for the /story tag
<story>
Hello there, I'm trying to build a semi-combat system for a small RPG that I am making. I'm to the part where I am trying to make a combat system based upon AD&D 2nd Edition Rules, that's Dungeons and Dragons. It involves rolling for initiative, rolling Thaco(Deciding whether or not you hit), and then deciding on how much damage is inflicted.
So as I was trying to automate the task of choosing who goes first(Initiative), the long process of writing the code came about and I realized that I will have to write the same code twice. Once for the monster going first and again for the character going first.
</story>
What I want to do is to write a function that goes into another function if the parameters are met and then that function will test some more variables and if the variables don't agree, the function will resume from whence it broke off into the new function.
ActionScript Code:
function attackAction(){
//Roll d10 for each party
cr=Math.round(Math.random()*9)+1;
this.cr_txt.text=cr;
er=Math.round(Math.random()*9)+1;
this.er_txt.text=er;
//If the enemies roll is greater, then have him attack first
if(er>=cr){
That's where a new function would come in. It would be something like
ActionScript Code:
function monsterTurn(){
//Test Thaco
if(Math.round(Math.random()*19)+1>=_root.monsterThaco){
//Roll for damage amount
damage=Math.round(Math.random()*_root.monsterAttack);
//Display message of Damage and takes damage from you
this.actions_txt.text="The Monster hits you for "+damage;
this.Health-=damage
//sees if the character is dead
if(this.Health<=0){
this.actions_txt.text="Oh no! You died";
}
else{
//Go back to the previous function and resume from there
Then of course there would be a playerTurn() that would do everything similar except test the player's variables.
<story>
If you're going to say that I should just have it list the commands, I tried that. It was far too long and complex to keep track of even with notes.
</story>
So can anyone help me out with Going through a function, hitting an if statement, going to a function based upon the statement, then testing a statement inside of the second function, then returning to the first function if the statement is false and doing the other part of the if statement in the first function.
It's difficult for me to explain this, but I hope you go the general jist. Thanks in advance.
View Replies !
View Related
Mysql->PHP->FLASH Function. (Passing Function To A Package)
I've just started with ActionScript3.0, and is currently working on a flash that is to communicate with a mysql database and have found a great deal of example code online that I've started to work with.
Currently I have the following package added to my project:
quote:package
{
import flash.events.*;
import flash.net.*;
public class SendAndLoad
{
public function SendAndLoad()
{}
public function sendData( url:String, _vars:URLVariables, completeFunc:Function ):void
{
var request:URLRequest = new URLRequest( url );
var loader:URLLoader = new URLLoader();
loader.dataFormat = URLLoaderDataFormat.VARIABLES;
request.data = _vars;
request.method = URLRequestMethod.POST;
loader.addEventListener( Event.COMPLETE, completeFunc );
loader.addEventListener( IOErrorEvent.IO_ERROR, onIOError );
loader.load(request);
}
//private function handleComplete( event:Event ):void
//{
//var loader:URLLoader = URLLoader( event.target );
//trace( "Par: " + loader.data.par );
//trace( "Message: " + loader.data.msg );
//}
private function onIOError(event:IOErrorEvent):void
{
trace("Error loading URL.");
}
}
}
And is running the following code in my flash:
quote:import SendAndLoad;
import flash.net.URLVariables;
function loadUsername( event:Event ):void
{
var loader:URLLoader = URLLoader( event.target );
//userNameText.text = "ffff";
userNameText.text = loader.data.user;
}
var url:String = "pages/test.php";
var vars:URLVariables = new URLVariables();
var sal:SendAndLoad = new SendAndLoad();
sal.sendData( url, vars, loadUsername );
As you can see I am trying to seperate the function to be called when the return value of the page I am accessing returns with a value, so I wont need to pass all different actions to be called on different pages I will be requesting throughout my flash program.
But as it is now, the function loadUsername, never even gets called, which I assume is because the package can't call the function outside it.
As I said, I am just starting out with ActionScript 3.0, and is kind of stuck at this.
Any thoughts?
Edited: 10/09/2008 at 08:46:50 AM by _TT_
View Replies !
View Related
Function That Wait's 5 Seconds And Runs Anothr Function
hy...I want to make a function that waits 5 seconds, after that to run another function that changes the content (changeContent) to the next label
this is all i managed to do...I hope it's wright
function autorun() {
if (button_label = 0) {
changeContent(1);
} else if (button_label = 1) {
changeContent(2);
} else if (button_label = 2 ) {
changeContent(3);
} else if (button_label = 3) {
changeContent(4);
} else if (button_label = 4) {
changeContent(5);
} else if (button_label = 5) {
changeContent(0);
}
}
I need this in AS2.0....
Can someone help me? Thanks!
View Replies !
View Related
[F8] [AS2] Access An Instance Variable From Within A Function Within Another Function
So here is the scenario that has completely stumped me. I have a class, within the class a function and within that function an xml onload handler. So herein lies the problem, I need to store the array of values that I receive from the XML into an instance variable belonging to the class. How can this be achieved?
To illustrate:
Class A {private var values:Array;public function getValues():Void{Xml sendandload code here.xmlReply.onLoad = function(){iterate through xml code and generate array of values.Store this array back into values belonging to class A}}}
using the variable straight up doesn't work.
if I use "this" it refers to the onload function, not the class.
i tried creating another class method called setValue and calling this.setValue(arr) and setValue(arr), but neither of those work.
i even tried combinations of _parent and this, still no go.
The only way I can get it to work is to make reference to _root.class.value, but this is not solid code and is very impracticale, especially if what calls the class doesn't happen to be in the root of the file.
Any ideas would be appreciated.
View Replies !
View Related
How Can You Make Sure One Function Completes Before Second Function Runs?
Hi guys:
I apologize if it's a really obvious answer, but I can't even think of the right terms to search on right now!
I have two functions. One is an xml connector trigger, that calls a PHP program to get xml data that includes content and formatting information. It will read the formatting information into hidden text fields.
The second function reads the hidden text fields, and applies the data from them to the style for the content fields:
Here's the prototype (pooh just being a "foo" name), contained in the root of the application:
Code:
// Initial poll for the XML data (this also runs the PHP that updates the movie)
var f_xml_trigger:Function = function(){
xml_community_board_connector.trigger();
}
_global.f_xml_trigger = f_xml_trigger;
// Function to apply styles:
var f_format:Function = function(){
Dashboard_Message_TextArea.setStyle("backgroundColor",Pooh.text);
}
_global.f_format = f_format;
_global.f_xml_trigger();
_global.f_format();
What's happening is _global.f_format is running before _global.f_xml_trigger has completed populating the fields.
I made these Global so a movie clip that's running a clock can periodically check for and apply updated content & formatting.
Code:
function getTime() {
var time = new Date();
<snip>
var second = time.getSeconds();
<snip>
if (second == 30 && _global.t30flag == 1)
{
// The _global.t30flag is used to make sure this only runs once
// otherwise it would run at the frame per second rate (i.e. 12fps = 12 times
// during the 30th second
_global.f_xml_trigger();
_global.t30flag++;
}
if (second == 31 && _global.t30flag == 2)
{
// Apply the formatting brought down by the xml trigger.
// Can't be done at the same time, because it runs before the values are updated.
_global.f_format();
_global.t30flag++;
}
<snip>
But rather than depending on frame numbers or seconds (especially since a 1 second delay between when text changes and formatting changes is annoying to say the least!)...I would think there must be a way that as soon as we can get a success returned from _global.f_xml_trigger we can run _global.f_format.
Any suggestions?
Thanks,
Matt
View Replies !
View Related
Using Variables Created Inside A Function Outside The Function?
I am trying to use a variable I am creating inside of a function, outside of that function, but I seem to have a scope issue when I do this.
My code is:
Code:
function drawlines(centerx, centery, radius, radians){
var radiansSoFar:Number = 0
var piechart:MovieClip = new MovieClip();
piechart.name = "piechart"
piechart.x = stage.stageWidth/2;
piechart.y = stage.stageWidth/2;
stage.addChild(piechart);
}
but I want to make a function outside of this which removes the variable piechart, but because im so unfamiliar with how flash names instances now I have no idea how to do this.
It works if I define var piechart:MovieClip = new MovieClip() outside of the function, but this isnt very useful as I eventually need to create multiple movieclips dynamically and name them dynamically.
So basically how would make it so I would be able to use the code
Code:
function removeChart(chartname){
stage.removeChild(chartname)
}
to dynamically remove a movieclip I created in a function?
View Replies !
View Related
Cannot Call Button Function Within Another Event Function
Hopefully someone can help me out with this one. I'm importing XML in order to draw images into an animated scrollbar, and would like to nest a button function within the function urlLoaded as listed below:
import caurina.transitions.*;
var urlCall:URLRequest = new URLRequest("pics/hotel_dreams/hotel_dreams.xml");
var urlLoader:URLLoader = new URLLoader();
var xml:XML;
var xmlList:XMLList;
urlLoader.load(urlCall);
urlLoader.addEventListener(Event.COMPLETE,urlLoade d);
var arrayThumb:Array = new Array();
var photoContainer:Sprite = new Sprite();
addChild(photoContainer);
photoContainer.mask=thumb_holder;
function urlLoaded(event:Event):void {
xml = XML(event.target.data);
xmlList = xml.children();
trace(xmlList.length())
for (var i:int=0; i<xmlList.length(); i++) {
var thumb:Thumbnail = new Thumbnail(xmlList[i].url);
arrayThumb.push(thumb);
arrayThumb[i].y = 67.5;
arrayThumb[i].x = xml.children().x_position[i];
photoContainer.addChild(thumb);
arrayThumb[i].gallery = xml.children().gallery[i];
trace(arrayThumb[i].gallery);
}
}
my hope is to create a button that looks something similar to the following in order to execute an if then statement within the function controlling the visibility of images from the XML based on their gallery property value.
btn_gallery_2.addEventListener(MouseEvent.CLICK, open_gallery_2);
function open_gallery_2(event:MouseEvent) {
if (arrayThumb[i].gallery == 2) {
arrayThumb[i].visible = true
}
}
I have been trying to nest within the urlLoaded function to no avail. By running trace statements I can see that [i] is inaccessible when nested within another function within urlLoaded and when completely outside of the urlLoaded function.
The Thumbnail class referenced is in an .as file that looks like this:
package {
import flash.display.Sprite;
import flash.display.Loader;
import flash.net.URLRequest;
public class Thumbnail extends Sprite {
private var url:String;
private var loader:Loader;
private var urlRequest:URLRequest;
public var gallery:Number
function Thumbnail(source:String):void {
gallery = 0
url=source;
drawLoader();
}
{
private function drawLoader():void {
urlRequest=new URLRequest(url);
loader=new Loader ;
loader.mouseEnabled=false;
loader.load(urlRequest);
loader.x=-0;
loader.y=-68
;
addChild(loader);
}}}}
I have the suspicion that I am missing something very basic. If anyone out there might be able to give me some insight, then I would be appreciative.
thanks very much
View Replies !
View Related
Is There A Limit To How Many Function Calls Are Made In A Function?
Hi,
I have a question on what is the limitation of the number of functions that can be called in Actionscript in a single "function." I use Flex to run all of my Actionscript listed beow.
Is there a certain number of if statements nesting only allowed in a single private function? I have a function call as in the following, and I wanted to add some other Alert statements to show users if there is an error in the process, but it appears that the file writing process is so long that I never see the Alert.show pop up.
Could anyone here please tell me what I might have done wrong here, since I could not get any Alert.show statements show up after scenario_save(1) or in scenario_save() function itself.
Question, if there is a limit to how many functions I can insert due to "time issues," is there a way I can get around it?
Thanks for your help.
Main Event Handler:
private function clickHandler3(event:ItemClickEvent):void {
if (String(event.index) == '0') {
currentState="";
}
if (String(event.index) == '1') {
scenario_find.send();
currentState="Scenario Show";
}
if (String(event.index) == '2') {
scenario_save(0); //The user would only save the scenario
}
if (String(event.index) == '3') {
//The user would save and run the scenario
scenario_name.send();
filename1.text= scenario_name.lastResult.scenarios.filename;
scenario_save(1); //Save record and output the file to filename1.text
//Execute the exe file and input entries back to the database
}
}
Child Function of Scenario Save:
private function scenario_save(x:int):void{
var pop:int= scenario_load.lastResult.scenarios.number_entries;
var pop2:int=scenario_load.lastResult.scenarios.number _entries-1;
number1.text= pop.toString();
if (pop2 == 0) { //if there is only one item, no index produced
i1.text= i.toString();
population1.text=scenario_load.lastResult.scenario s.scenario.population;
region_id1.text=scenario_load.lastResult.scenarios .scenario.region_id;
query1.text= "UPDATE My_Scenario SET Population='" + population1.text + "' WHERE Region_id='" + region_id1.text + "' AND ID='" + id1.text + "'";
hello1.text=region_id1.text + " " + population1.text;
update_record.send();
if (x==0) {
//Don't do anything, since there is nothing to run
} else if (x==1) {
execute_scenario.send();
}
}
else {
for (var i:int=0;i<=pop;i++) { //if there are more than one item, indices would be produced
i1.text= i.toString();
population1.text=scenario_load.lastResult.scenario s.scenario.population;
region_id1.text=scenario_load.lastResult.scenarios .scenario.region_id;
query1.text= "UPDATE My_Scenario SET Population='" + population1.text + "' WHERE Region_id='" + region_id1.text + "' AND ID='" + id1.text + "'";
hello1.text=region_id1.text + " " + population1.text;
update_record.send();
if (x==0) {
//Don't do anything, since there is nothing to run
} else if (x==1) {
execute_scenario.send();
//I want to add some other alert statements here, but they are not working
}
}
}
}
View Replies !
View Related
OOP In Flash: Calling A Function W/in A Function Class?
Okay so I am reading through sens tutorial on OOP and updating my game that I am making. It is much easier to code this way (IMO) but still hitting snags.
I am trying to get through this code:
ActionScript Code:
House = function(){ this.floors = 4; this.siding = "Red"; this.outputSiding = function(){ trace(this.siding); }; }; // create an instance of the House class myHouse = new House(); myHouse.outputSiding(); // traces "Red"
Now as it seems to me, I have nearly the same thing (I will condense this to save space):
ActionScript Code:
//set new character function()character = function (depth, x, y, charType, name, HP, MP) { //sets stats used; this works fine :) //attachMovie and set x/y _root.attachMovie(this.name+"_mc", this.name+"MC", this.depth, {_x:this.x,_y:this.y}); /*this is where I am having trouble; it won't do anything!I have tried tracing to no availalso, can I set the x and y coords somehow with thealready made object x and y? I am tired right now andcan't think of a way but what I have done, which doesnothing as this function won't go!*/ statsBox = function(depth) { this.depth = depth; trace(this.depth+newline+'hello'); this.x = enemy._x+130; this.y = enemy._y-50; _root.attachMovie("stats_mc", statsNameMC, this.depth, {_x:this.x,_y:this.y}); };};enemy = new character(30, 350, 200, 'enemy', 'genericName', _root.EHP, _root.EMP);enemy.statsBox(50);
that's it, pretty much. So what's wrong? Maybe I'm too tired for this right now...
thanks.
View Replies !
View Related
Cant Remove Event Listener (function In A Function)
I have this function, that when given a movie clip and a destination, it moves it to there, and eases out.
I have buttons that control where it moves to. This all works great.
But I want it so that if it is moving, and a new destination is clicked, it stops and moves to the new destination.
When I remove the event listener, nothing happens. But the event listener removes properly when it stops. (just wont when it is moving)
So the tricky part is this. I have a function in a function, It is there so the moving event:enter_frame parrt can see the same variables passed to it from the click.
If I move this function out of the other function, I can remove it. But it can not access the variables and does not move.
Part that does not work
if (isMoving == true) {// are we moving?
trace('is moving:'+isMoving);
removeEventListener(Event.ENTER_FRAME, mover);// stop moving
PHP Code:
function easeTo(toMove:MovieClip, dest:Number):void {
trace(toMove +' is being moved to: '+ dest);
if ( toMove.x != dest ) {//are we already there? If so, do nothing
if (isMoving == true) {// are we moving?
trace('is moving:'+isMoving);
removeEventListener(Event.ENTER_FRAME, mover);// stop moving
} else {// not moving, set dest and go.
trace('is moving:'+isMoving);// reads faluse
isMoving = true;// now set to true
addEventListener(Event.ENTER_FRAME, mover);// start moving
}
} else {
trace('we are already there');// do nothing
}
function mover(event:Event) {// move. Function here because it needs to access internal varibles
if (Math.abs(dest - toMove.x) < 1) { // are we there? yes? stop event listener
removeEventListener(Event.ENTER_FRAME, mover);
isMoving = false;
wDirection = '';
} else {
toMove.x += (dest - toMove.x) * speed;
}
}
}
View Replies !
View Related
OOP In Flash: Calling A Function W/in A Function Class?
Okay so I am reading through sens tutorial on OOP and updating my game that I am making. It is much easier to code this way (IMO) but still hitting snags.
I am trying to get through this code:
ActionScript Code:
House = function(){ this.floors = 4; this.siding = "Red"; this.outputSiding = function(){ trace(this.siding); }; }; // create an instance of the House class myHouse = new House(); myHouse.outputSiding(); // traces "Red"
Now as it seems to me, I have nearly the same thing (I will condense this to save space):
ActionScript Code:
//set new character function()character = function (depth, x, y, charType, name, HP, MP) { //sets stats used; this works fine :) //attachMovie and set x/y _root.attachMovie(this.name+"_mc", this.name+"MC", this.depth, {_x:this.x,_y:this.y}); /*this is where I am having trouble; it won't do anything!I have tried tracing to no availalso, can I set the x and y coords somehow with thealready made object x and y? I am tired right now andcan't think of a way but what I have done, which doesnothing as this function won't go!*/ statsBox = function(depth) { this.depth = depth; trace(this.depth+newline+'hello'); this.x = enemy._x+130; this.y = enemy._y-50; _root.attachMovie("stats_mc", statsNameMC, this.depth, {_x:this.x,_y:this.y}); };};enemy = new character(30, 350, 200, 'enemy', 'genericName', _root.EHP, _root.EMP);enemy.statsBox(50);
that's it, pretty much. So what's wrong? Maybe I'm too tired for this right now...
thanks.
View Replies !
View Related
Pausemovie Function Inside Fadein Function
Last edited by pusherman : 2007-06-21 at 10:26.
I am trying to merge two functions together. The result is however, pausemovie function does not work (perhaps overriden by onEnterFrame) and mypic's alpha reaches 100 by increments of 7.
ActionScript Code:
//MC:mypic1 appears.
createEmptyMovieClip("fadein", 222);
fadein.onEnterFrame = function() {
pauseMovie(4);
if (mypic1._alpha<100) {
mypic1._alpha += 7;
} else {
removeMovieClip("fadein");
}
};
My pausemovie function is on my 1st frame and is as follows:
ActionScript Code:
function pauseMovie(seconds) {
stop();
var startTime = getTimer();
var endTime = seconds * 1000;
this.onEnterFrame = function(){
currentTime = getTimer();
if(currentTime - startTime > endTime){
//this is where your action goes
play();
delete this.onEnterFrame
};
};
};
I would appreciate any help.
Thank you.
View Replies !
View Related
Target A Function In A Function In A Object :)
Uggg, how do I target a function that is in a function that is in an Object...
I am building a componet and when the componet runs though the script and finishes I want to call a genral function that will be replaced with a spacific function that I set in the Componets Properties window.
So my Object function X2 looks something like this...
ScalerClass.prototype.clipEndAction = function(loadHandler) {
loadHandler();
};
ScalerClass.prototype.myOtherFunction = function(){
trace("This function is a function")
}
//now if I target it like this within the object it works fine.
loadHandler=myOtherFunction
this.executeCallBack(loadHandler);
But How do I set up so that if this is in an componet i could target it from the Componets Pro Win.
View Replies !
View Related
Passing A Function Ref To A Function With Parameters
Can anyone tell me how to pass a function reference to a function WITH parameters?
I want to do something like this:
genericFunc = function(funcRef, params){
//do something that takes a while
//and when done...
//call my funcRef with params:
funcRef(params)
}
func1 = function(){
//trace("here's funct#1");
}
func2 = function(arg1, arg2){
//trace("here's func#2 with arguments "+arg1+" and "+arg2);
}
Test 1: genericFunc(func1);
Test 2: genericFunc(func2, ...) //this is where I lose it.
So, this works fine if I'm passing in a function call that requires no parameters (test 1). But what I really need to do is keep this flexible so that I can reference different functions with varying numbers of parameters (test 2).
View Replies !
View Related
Regular Function? Prototype Function?
I have a bunch of mc's on the stage. Currently, the actionscript making them rotate is the same for each one exept 3 numbers. I was wondering. If I made each of those parts (times to loop, rotaion amount, counter amount) variables, couldn't I just set them for each one, then run a function usinig the updated info? Where do I declare it? In every mc, one mc, or the frame? Last time I put it in the frame and used "this" the whole movie rotated! If you need a better look, here is the file:
View Replies !
View Related
[F8] Calling A Function Froma Function
Please excuse my ignorance, but can i call a function from a different function. I'm not sure how to do it.
eg:
myBut.onPress = function ()
{
_root.currentimage=1;
_root.crumb.titles="/fashion&lifestyle";
_root.loadLeft._visible=0;
FashStrip.mc01._alpha = 60;
}
how do i integrate this into the above function?:
function fadeOut()
{
extendTween = new TweenExtended(_root.loadLeft.fashThumb,["_alpha"],
easingType4,[_root.loadLeft.fashThumb._alpha],[0],1,true);
}
i know i could put it straight in the button function but i want to reuse the fadeOut function again many times!!! (just learning to keep my code nice and neat)
Rat
View Replies !
View Related
Function Literal Vs Function Calls
Hello,
Can anyone explain to me the difference in using one or the other function methods? Or can shed light if there exists any coding advantages in using one method or the other?
myfunction = function(){
trace(this);
}
function myfunction(){
trace(this);
}
Thank You
View Replies !
View Related
[F8] How Do You Call A Function In A Function In A Class?
I have this class..
class Bob {
function Bob(){
initiate code
}
function loadImages(){
Load images code...
image.onEnterFrame = function(){
if loaded {
this.nextFunction();
}
}
}
function nextFunction(){
do this
}
}
basically, i have a function that loads images.. and i need to have it automatically do another function in that class once the images are loaded..
how do i wait til they're loaded in the class? cause if i put it in "onEnterFrame" , 'this' no longer refers to the class, it refers to the onEnterFrame..
so how do i refer back to the class?
or how do i determine if the images are loaded all in the one class?
View Replies !
View Related
Call Function From A Function In A Class?
i havee..
class testClass
{
function testClass()
{
giveFunctions(mc1);
}
function traceIt(tag)
{
trace(tag);
}
function giveFunctions(mc:MovieClip)
{
mc.onRollOver = function()
{
traceIt("SUP");
}
}
}
How do i make the giveFunctions function access the class?
cause it defines a rollover function for an MC.. but in that rollover function, it has to re-reference a different function in the class..
how does that work?
there'll be more variables and it'll be more complex..
I had like,
function giveFunction(mc:MovieClip,tag)
{
mc.sett = this.traceIt;
mc.mca = mc;
mc.tag = tag;
mc.onRollOver = function()
{
this.sett(this.mca,this.tag);
}
}
that works, but it like.. pulls the traceIt function out of the class so it couldn't reference any other variables if it needed to
View Replies !
View Related
Return Function Name (Function => String)
I keep coming across problems where it would be really convenient to get the name of a function in string format - like arguments.callee only a string instead of [Function, Function].
I haven't thought of a way to do this but in my head the keywords 'prototype' and 'override function' keep coming up - albeit that seems like a horrible horrible idea, but Function does extend Object so...thoughts?
View Replies !
View Related
Function Returning Function With Delay
Is it possible to create a functionA, which returns another functionB with a delay? I need to check if XML is loaded before functionB is executed.
Here is what I've done:
PHP Code:
private function XYZ():void {
checkXML(doFc).apply(this);
function doFc():void {
info.text = "here Iam";
}
}
private function checkXML (fce:Function):Function {
var thisFc:Function;
if (xmlLoaded) {
thisFc = fce;
} else {
container.addEventListener(Event.ENTER_FRAME, xmlCheck);
}
function xmlCheck (e:Event) {
if (xmlLoaded) {
container.removeEventListener(Event.ENTER_FRAME, xmlCheck);
thisFc = fce;
}
}
return thisFc;
}
This works fine when xmlLoaded is true. But in case it's not, there is xmlCheck function which sends the result later. But in the mean-time is returned empty function.
Do you have any suggestions?
Thanks
View Replies !
View Related
|