AS3 :: Flash - Smooth Custom Movieclip Repel Function?
Oct 30, 2010
I wrote this repel function (below) for 2 movieclips and I call it from a timer instead of an enter_frame listener (speed), but it has the tendency to jerk and not be very smooth. How can I smooth the movements?
function repel(mover2, mover) {
var xdiff:Number = mover2.x - mover.x;
var ydiff:Number = mover2.y - mover.y;
var dist:Number = Math.sqrt(xdiff*xdiff + ydiff*ydiff);
[code]....
View 1 Replies
Similar Posts:
Mar 4, 2011
I'm trying to build an application where the themouse cursor is used to "blow" a movieclip around. The way I'm doing this is by making the mouse cursor repel the movieclip. The problem is, I can only get it to work on the top and the left of the movieclip.
Here's my code:
function moveCloud(event:Event):void {
var yChange:Number = Math.round(mouseY-cloud.y);
var xChange:Number = Math.round(mouseX-cloud.x);
[code]....
View 1 Replies
Sep 2, 2011
I'm a bit slow when it comes to grasping this whole concept.
I am after a script that allows me to use my mouse and repel objects within the canvas in Flash. For example, if I move my mouse close to a shape, say a circle, the shape would immediately dodge the mouse.
View 2 Replies
Nov 2, 2006
I'm trying to assign a custom property to an attached MC. In this case it's an ID number, but it's always undefined inside the onRelease function... What am I missing?
ActionScript Code:
function blablaMethod(){_root.attachMovie("bla", "bla"+someIncrementingId, _root.getNextHighestDepth());var mcReference = _root["bla"+someIncrementingId];// I've also tried the following:var mcReference = _root.attachMovie("bla", "bla"+number, _root.getNextHighestDepth());
[code]....
View 2 Replies
Apr 1, 2008
I want to call a function from another function's parameter but I don't know how and don't know if it is possible.I've considered this as a solution but it didn't worked.
Code:
function myFunc(target_mc:MovieClip, nX:Number, nY:Number, cFunc:Function) {
target_mc._x += nX;
targen_mc._y += nY;
target_mc.onPress = cFunc;
[code]....
View 2 Replies
Jul 23, 2009
having trouble with this .fla (attached) i have an object on the stage and I want to be able to make it repel the mouse cursor, similar to a magnet, so you cant get near it...
The MC is called BOX and this code I have on the frame...
var dist = 30;
var objx = box._x += (box._width/2);
var objy = box._y += (box._height/2);
[Code].....
View 1 Replies
Jan 20, 2012
I have a coin MovieClip which revolves around different orbits in my puzzle game.
[Code]...
View 2 Replies
Feb 9, 2004
I have a movieclip that I want to be resized when a button is clicked. I want the animation to be smooth as if it had weight though. I read the tutorial on this but I need something slightly different, I would rather it where I can just refer to a function that is set in another movieclip. That way I could easily refer to it again and just set the height, width, and if possible, x, and y.
And my second question, is how to keep the border of my movieclip that is going to be resized the same thickness. I want the inside to be resized but the sides to stay the same width but move to stay on the edge.
View 8 Replies
Dec 7, 2004
I have the following script in both frame 1 and 2 to let a movieclip move from right to left on the stage:
Code:
speed =-5
name._x += speed
if (name._x<-500) {
name._x = 250;
}
And the clip is indeed moving from right to left on the stage and when it reaches _x -550 it is going back to it's starting position _x 250 only the movement isn't smooth at all. What should I do to make the movement more smooth or should I use a completely different script?
View 6 Replies
May 19, 2010
I want to make a movieclip moves smoothly and when it changes the direction, it can turn smoothly but not a sudden turn, I try out the code below. and the truning is odd:
this.rotation = (Math.atan2(targetY-this.y, targetX-this.x )/Math.PI)*180;
View 2 Replies
Dec 7, 2004
I have the following script in both frame 1 and 2 to let a movieclip move from right to left on the stage:
[Code]...
And the clip is indeed moving from right to left on the stage and when it reaches _x -550 it is going back to it's starting position _x 250 only the movement isn't smooth at all. What should I do to make the movement more smooth or should I use a completely different script?
View 6 Replies
Nov 29, 2004
I'm using Flash MX 2004.
[Code]...
Can you please tell me why this isn't working? It takes me 10 minutes to test the movie every time and it's taking me forever to fix things. Do I have to do something else with the variable names I'm using or something?
View 2 Replies
Jun 4, 2010
i'm trying to cast a MovieClip to a custom Class that extends MovieClip called MovieClipExt
ActionScript Code:
package {
import flash.display.MovieClip;
[Code]....
...but sadly returns null instead of a MovieClip converted to MovieClipExt
what should i change to make this work?
View 3 Replies
Oct 24, 2010
I have movieclip which contains child movieclip. when child movie clip finish to play i want to run a function in a parent movieclip. so I made a custom event dispatcher in the first frame of the child movieclip:
[Code]...
View 4 Replies
Apr 1, 2011
I have a document class called Main.as In the class constructor I have the following listener:
enter code here
var listeningFORModeChangeToStudent:Sprite = new Sprite;
listeningFORModeChangeToStudent.addEventListener(TellAllModeChangeToStudent.STUDENT,exp);
addChild(listeningFORModeChangeToStudent);
[code]....
In a third class I make a call to the despatcher in the previous class:
enter code here
var ThisTellAllModeChangeToStudent:TellAllModeChangeToStudent = new TellAllModeChangeToStudent;
ThisTellAllModeChangeToStudent.tellAllModeChangeToStudent();
I have trace statements in eveything and from this I know the despatcher in TellAllModeChangeToStudent is being called.The problem is that the listener in the main.as is not calling the function exp.I cant see why and I dont know how to check if the listener is actually seeing the dispatch event?
View 1 Replies
Jan 23, 2010
I am new to AS3, as well as Flash in general, so forgive me if this seems highly elementary. All I am trying to do is create a custom class that extends the MovieClip class and contains a custom property of "marker". I want to be able to use and change the value of this custom property on the timeline for an instance of this class and have it behave just like any other (Ex: this.x ==> this.marker).
[Code].....
View 13 Replies
Dec 11, 2010
In the main file, I would write[code]...
But if I want the component to have that behaviour innately, where do I write it in the mybutton mxml file to have it reference itself?[code]...
View 2 Replies
May 5, 2006
I tried "attaching" a custom context menu on the 'picture' movieclip (empty movieclip that holds externally loaded pics) but with no luck.
View 1 Replies
Sep 2, 2009
i have a set of "if conditionals" that should always be together,what i want to do is to put these conditionals in a function... then call the function once needed. i want to call this function once the flash starts playing + when i click on any of the 3 buttons.
here is the code so far:
ActionScript Code:
var btn1:Boolean=true;
var btn2:Boolean;
var btn3:Boolean;
[code]....
the problem is button1 should have no eventlistener once the movie starts playing, but it has all listeners... so how can i make AS reads BtnStatus function once it starts loading
View 2 Replies
Mar 27, 2010
I have a game and i use function gotoAndStop in actionscript to play frame "moving" in my character game.And in this frame have movieclip. How can i detect when movieclip inside frame "moving" end ?
View 1 Replies
Jul 29, 2009
The fact is that the "dispatchEvent" method must be placed into the code or timeline where the "event" happens, then it can be trigged and the function associated with the event will be invoked. Ok, it is understood. Nevertheless, my question is: what's the point to create an event to trigger the a function call, if I can simply call the function instead directly???
Code:
package{
import flash.events.Event;
public class CustomEvent extends Event{
public static const ONSOMETHING:String = "onSomething";
public function CustomEvent(type:String){
super(type);
[Code] .....
If I can do simply:
Code:
DoIt();
function DoIt(){
trace ("Done!");
}
What I mean is that custom events doesn't look like as REAL events for me, but more like a delegate way to call a function. Differently from Flash native events that are controlled by an internal engine that keep checking if the event happened, in the custom events they must triggered 'manually', and it seems to lose the event main characteristic.
View 6 Replies
Jun 6, 2011
I am trying to sort big array using actionscript 3. The problem is that i have to use custom sorting function which is painfully slow and leads to flash plugin crash.
Below is a sample code for custom function used to sort array by length of its members:
[Code]...
View 3 Replies
Dec 26, 2009
I want to be able to make my own math-functions, so that I don't have to write the same trivial functions in all my classes. I would like to import a class called something like MathExtended, and then use functions like this:
MathExtended.sign(x)
I have made an example that tries to import a custom class like that:
Code:
/*
This is the main script which my fla. runs.
*/
[Code].....
View 3 Replies
Mar 18, 2011
ActionScript Code:
private function drawMap(tile1:DisplayObject, tile2:DisplayObject):void
{
var _tile1 = tile1;
[Code].....
The idea behind this is to store custom sprites in an array and then feed the array to the drawMap function, which would use the sprites from the array to draw a map.
View 1 Replies
Jul 8, 2011
I'm trying to fade a piece of text that I'm loading via XML in and out (as well as moving it's location in and out).* The fade out part is working fine, and as long as I have a _alpha.100 command where I'm currently calling my "slidein" function (really the fade in function) it works fine. No idea why! I've tried about 100 different placements and I'm stumped.. It's very perplexing.*
ActionScript Code:
function loadXML(loaded) {
if (loaded) {
[code].....
View 2 Replies
Jun 30, 2009
I'm trying to create a custom sort function. This function will sort the pegs in a certain row by their row number (0: lowest -- numRows - 1: highest)For context, here is Adobe's description for the Array sort method: http://livedocs.adobe.com/flash/9.0/ActionScriptLangRefV3/Array.html#sort()
My array-building function:
Code:
public function getPegsInRow(row:int):Array
{
var pegRowArray:Array = new Array()
for(var i:int = 0; i < pegArray.length; i++)
[code]....
Unfortunately, the array does not get sorted correctly.
View 3 Replies
Aug 20, 2009
I've been trying to find an easing generator that supports bounce but have found none. I want to create an easing function that starts as a easeInSine (or quad) and ends as en easeOutBounce (imagine dropping an object on the ground). I've already thought of splitting up the tween in two. Just realised that the easeOutBounce actually starts a little bit like easeInSine but I would like to enhance that part to make a steeper curve.
View 4 Replies
Feb 21, 2012
I created a function with input variables, so I don't have to repeat this function X amount of times. But within the function is a TweenLite call and that call has an onComplete. This onComplete somehow doesn't understand what the variables filled in in my function represent.
PHP Code:
function navMenuInput(check01:Boolean, check02:Boolean, movieClip01:MovieClip, movieClip02:MovieClip){ if(check01 == true && check02 == false){ if(movieClip02.stage){ TweenLite.to(movieClip02, 1, {alpha: 0, onComplete: navMenuInputComplete} ); }else{ navMenu.addChildAt(movieClip01, 0); movieClip01.x = navMenu.width-
[code]...
EDIT:I think I can make this a bit more clear when I explain what this is supposed to do:This menu can reach it's end via different routes. So the user can choose Path A or B, but what I'm trying to set up here is. If A is on stage, A should be removed first before B is placed and vice versa. And because this happens for about 4-5 times I wanted to shorten the code by using something like this.
View 4 Replies
Nov 29, 2004
I'm using Flash MX 2004.
PHP Code:
// function to automate the hit tests
function hitClip (aCPlaceNum, loopNum, loopName, aCButtonNum) {
[code]....
View 2 Replies
Apr 24, 2010
I'm building a flash app that pulls images from flickr and removes the white background. I'm doing this using threshold and I get a really ragged outcome. Is there any way to get a better and smoother color key?
photoNumber = Math.floor(Math.random() * (photos.length));
loader.load(new URLRequest(photos[photoNumber].path));
loader.contentLoaderInfo.addEventListener(Event.COMPLETE,draw);
trace ( "trying to load photo " + photoNumber );
function draw(e:Event) {
[Code] .....
View 2 Replies