Tracking Forums, Newsgroups, Maling Lists
Home Scripts Tutorials Tracker Forums
  Advanced Search
  HOME    TRACKER    Flash








[FMX]Changing A ClipEvent Into A Function


I have the following clipEvent to control a scrolling menu:


Code:
onClipEvent (load) {
xcenter = 250;
speed = 1/15;
}
onClipEvent (enterFrame) {
var distance = _root._xmouse-xcenter;
_x -= (distance*speed);
if (_x>0) {
_x = -500;
}
if (_x<-500) {
_x = 0;
}
}
How can I make this into a function ?




KirupaForum > Flash > ActionScript 1.0/2.0
Posted on: 04-16-2004, 11:51 AM


View Complete Forum Thread with Replies

Sponsored Links:

[FMX]Changing A ClipEvent Into A Function
I have the following clipEvent to control a scrolling menu:


Code:
onClipEvent (load) {
xcenter = 250;
speed = 1/15;
}
onClipEvent (enterFrame) {
var distance = _root._xmouse-xcenter;
_x -= (distance*speed);
if (_x>0) {
_x = -500;
}
if (_x<-500) {
_x = 0;
}
}
How can I make this into a function ?

View Replies !    View Related
Function/clipEvent Help
I have 2 movieclips on my stage (box_mc, box2_mc), each contains a button(my_btn). box2_mc starts off with an _alpha of 0 while box_mc starts off with an _alpha of 100. When a button in box_mc is pressed it will fade box2_mc in and fade box_mc out and vice versa. What I would like some help with is creating a function that will fade 1 movie clip out and when that clip's _alpha has reached 0 it will start to fade the other clip in. Any help with this would be great. Here's my code so far:
code:
var fadeBox:Number;
var fadeBox2:Number;
box_mc.my_btn.enabled = true;
box2_mc.my_btn.enabled = false;


box_mc.my_btn.onRelease = function() {
box_mc.fadeBox = 0;
box2_mc.fadeBox2 = 100;
box_mc.my_btn.enabled = false;
box2_mc.my_btn.enabled = true;
}
box2_mc.my_btn.onRelease = function() {
box_mc.fadeBox = 100;
box2_mc.fadeBox2 = 0;
box_mc.my_btn.enabled = true;
box2_mc.my_btn.enabled = false;
}

clipEvent
code:
onClipEvent(enterFrame) {
_alpha += (fadeBox - _alpha) / 5;
}
onClipEvent(enterFrame) {
_alpha += (fadeBox2 - _alpha) / 5;
}

View Replies !    View Related
ClipEvent To Function
Hi,

I have used the following onClipEvent to move a menu according to the x position of the mouse:


Code:
onClipEvent (load) {
xcenter = 250;
speed = 1/15;
}
onClipEvent (enterFrame) {
var distance = _root._xmouse-xcenter;
_x -= (distance*speed);
if (_x>0) {
_x = -500;
}
if (_x<-500) {
_x = 0;
}
}
Is this script also possible in a function and if yes how does that function look likes .

Thanks in advance

View Replies !    View Related
[FMX]clipEvent To Function ?
I have the following clipEvent on a movieclip called square:

onClipEvent (enterFrame) {
xmove = (xpos-this._x)/5;
this._x += xmove;
}

And the following framecode in the same keyframe as square:

_root.square.xpos = Math.round(Math.random()*550);

Now I want to convert this into a function so I can control more than just one clip for the random movement.

Can anybody tell me how this function should look like?

View Replies !    View Related
STUCK AGAIN: Move A 'clipevent Code' Into The Main Timeline 'function' - HELP
I wonder if any on can help me here with this...this is my script that is attached to movie clips which ar erandomly placed on the screen and walk about at random angles and speeds.

-------------------------------------------------------------
-------------------------------------------------------------
onClipEvent (load) {
sx = random(4)+4;
sy = random(6)-6;
if (_name != "ganga") {
_x = Math.random()*750+25;
_y = Math.random()*550+25;
this.gotoAndPlay(2);
}
}
onClipEvent (enterFrame) {
if (_name != "ganga") {
_x += sx;
_y += sy;
// these may not be needed if it never just goes in one direction:
if (sx == 0 && sy<0) {
// just up
this._rotation = 0;
}
if (sx == 0 && sy>0) {
// just down
this._rotation = 180;
}
if (sx<0 && sy == 0) {
// just left
this._rotation = 270;
}
if (sx>0 && sy == 0) {
// just right
this._rotation = 90;
}
if (sx>0 && sy == 0) {
// just right
this._rotation = 90;
}
// directions:
if (sx>0 && sy<0) {
// 9
this._rotation = 45;
}
if (sx>0 && sy>0) {
// 3
this._rotation = 135;
}
if (sx<0 && sy>0) {
// 1
this._rotation = 225;
}
if (sx<0 && sy<0) {
// 7
this._rotation = 315;
}
if (_x<25) {
_x = 25;
if (sy != 0) {
sx *= -(random(2));
} else {
sx *= -1;
}
if (random(2)) {
sy = 2;
} else {
sy = -2;
}
} else if (_x>775) {
_x = 775;
if (sy != 0) {
sx *= -(random(2));
} else {
sx *= -1;
}
if (random(2)) {
sy = 2;
} else {
sy = -2;
}
}
if (_y<25) {
_y = 25;
if (random(2)) {
sx = 2;
} else {
sx = -2;
}
if (sx != 0) {
sy *= -(random(2));
} else {
sy *= -1;
}
} else if (_y>575) {
_y = 575;
if (random(2)) {
sx = 2;
} else {
sx = -2;
}
if (sx != 0) {
sy *= -(random(2));
} else {
sy *= -1;
}
}
}
}
------------------------------------------------------------
------------------------------------------------------------
But what I want to do since i'm using MX is put all this into a function on the main timeline...but i can't get it to work! any ideas anyone...the mc are all on the root.

this is what I created, but as I said it doesn't work:

-----------------------------------------------------------------
-----------------------------------------------------------------
function walkFree() {
if (_name != "ganga") {
for (i=1; i<=amount1; i++) {
_x += _root["ganga"+i].sx;
_y += _root["ganga"+i].sy;
sx = _root["ganga"+i].sx;
sy = _root["ganga"+i].sy;
}
// these may not be needed if it never just goes in one direction:
if (sx == 0 && sy<0) {
// just up
this._rotation = 0;
}
if (sx == 0 && sy>0) {
// just down
this._rotation = 180;
}
if (sx<0 && sy == 0) {
// just left
this._rotation = 270;
}
if (sx>0 && sy == 0) {
// just right
this._rotation = 90;
}
if (sx>0 && sy == 0) {
// just right
this._rotation = 90;
}
// directions:
if (sx>0 && sy<0) {
// 9
this._rotation = 45;
}
if (sx>0 && sy>0) {
// 3
this._rotation = 135;
}
if (sx<0 && sy>0) {
// 1
this._rotation = 225;
}
if (sx<0 && sy<0) {
// 7
this._rotation = 315;
}
if (_x<25) {
_x = 25;
if (sy != 0) {
sx *= -(random(2));
} else {
sx *= -1;
}
if (random(2)) {
sy = 2;
} else {
sy = -2;
}
} else if (_x>775) {
_x = 775;
if (sy != 0) {
sx *= -(random(2));
} else {
sx *= -1;
}
if (random(2)) {
sy = 2;
} else {
sy = -2;
}
}
if (_y<25) {
_y = 25;
if (random(2)) {
sx = 2;
} else {
sx = -2;
}
if (sx != 0) {
sy *= -(random(2));
} else {
sy *= -1;
}
} else if (_y>575) {
_y = 575;
if (random(2)) {
sx = 2;
} else {
sx = -2;
}
if (sx != 0) {
sy *= -(random(2));
} else {
sy *= -1;
}
}
}
}
------------------------------------------
-----------------------------------------------------

this is called from in the on clip event within the mc's they also have the top part as there onclipevent load:
----------------------------------------------------------------------
onClipEvent (load) {
sx = random(4)+4;
sy = random(6)-6;
if (_name != "ganga") {
_x = Math.random()*750+25;
_y = Math.random()*550+25;
this.gotoAndPlay(2);
}
}
onClipEvent (enterFrame) {
walkFree;
}
------------------------------------------------------------------------

please help!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!STU

View Replies !    View Related
Clipevent Help
please indulge me if you have read this before but i'm really stuck... sorry it's long, just trying to be thorough...

i'm doing a flash presentation and want it to function the same way as a ppt presentation (user hits the space bar, it advances forward, back key and it goes back one).

I know you can easily do this with buttons, but I was trying to avoid that. So i tried using a clip event (the different sections of my presentation are built in movieclips) that states:

onClipEvent (keyDown) {
play ();
}

The problem is when it gets to the end of that movie clip, it just goes back to the beginning of the same one (mc) and starts to play it over again. I want it to advance to the next movieclip on the main timeline. I'm not sure how to get the clipevent to recognize when it is at the end of the designated movie clip and begin playing the next mc.

Is there some other action I could be using? Do I need to set this up in a different way?

PLEASE HELP ME!

View Replies !    View Related
On Clipevent In Flash 4
Hi,
Is there a way to perform the same action as the "On Clipevent" from flash 5 in flash 4?

View Replies !    View Related
SetInterval Within ClipEvent?
Using Flash MX, can you call a setInterval within an onClipEvent (enterFrame) on a MC? I've tried testing this and it won't work.

View Replies !    View Related
ClipEvent Not Counting Right
I have a quiz built using the flash interactions and it's great. I have it plugged into my LMS and everything is tracking wonderfully except my results page.

I have 3 dynamic text fields on stage, and I want them to display how many right, how many wrong, and percentage.

Now....

When the user clicks a choice in a multiple choice for example I have this code:

onClipEvent(mouseUp){
_global.wrong = _global.wrong += 1;
}

The problem is whenevr the mouse is clicked on any frame this value gets added to. So in the end it will say 10 wrong out of 5.

I want a variable named wrong and a variable named right to be added to only when the user clicks the distractor.

I'm I making sense?

-Lemorris

View Replies !    View Related
ClipEvent Problem
I need some help with a clipEvent. Right now I have two clips(clients_display_mc, work_thumbs_mc) fading out, when the clip is faded out another clip(content_area_mask_mc) slides into position. Once that clip has reached it's new _x spot I want another clip(work_mc) to fade in. Currently I have the first two clips fading out fine and the second clip sliding into position, but I can't get the last part of my clip even to fire telling the last clip to fade in. Any suggestions would be greatly appreciated.


Code:
_root.checker_mc.onEnterFrame = function() {
if (_root.content_mc.clients_display_mc._alpha > 0) {
_root.content_mc.clients_display_mc._alpha -= 10;
_root.content_mc.work_thumbs_mc._alpha -= 10;
} else {
_root.content_mc.content_area_mask_mc.endX = 10;
if (_root.content_mc.content_area_mask_mc._x >= 10) {
_root.work_mc._alpha += 10;
if (_root.work_mc._alpha >= 100) {
deletethis.onEnterFrame;
}
}
}
};

View Replies !    View Related
Screed Against On(clipEvent)
I am continually amazed at the number of people who are just now coming to Flash (or have only just started learning a bit of Actionscript) and post questions regarding on(someClipEventOrOther). I'm trying to understand who and/or what is guiding them to using this type of pre-Flash MX (6) style of coding.

Flash 6 was released early in 2002 and introduced all the MovieClip.onSomeClipEventOrOther events. The benefits of being able to put all your code in one place (or at least in more controlled places) and not having to search around to make changes are truly amazing. Personally I haven't used the on(clipEvent) structure since 2002. And I suspect that most folks here who do a lot of development use it very sparingly if at all? Am I correct in this assumption?

Personally I seldom answer questions that involve that kind of code because I just don't remember all the in-outs-and-little-tricky-bits about using it. Scoping issues, does the clip exist at the correct time, what is the path from it to other things on the stage, what is their code and properties, etc. It just gets too hard to debug and follow when it is so broken up. Or maybe it is just me?

I'm just trying to start a community dialog about this and am wondering if there is someway we can encourage/lead new folks to not using that style of coding? Or does everyone think that it is a good thing?

PS: I used to be crazy and rabid about the use of _root, and I would just like to point out that we don't seem to have so many questions that revolve around _root anymore, now do we? :)

View Replies !    View Related
Refresh ClipEvent
Hello:
I have a blank container mc into which I am loading JPGs after you click on a button.
There are 10 buttons in the movie, each associated with a different JPG.
This container_mc is part of a function called on the main Timeline.
The Flash movie is 1 frame on the main Timeline.
This code works correctly on the first JPG when I click on a button for the first time), but then when you click on a different button I believe it just uses the dimensions and coordinates of the first JPG.
How can I reset or refresh (unload, reload?) this function so it works correctly every time I load a new JPG?
updateAfterEvent, maybe?
thanks.
//after full size image loads into detailthumb_mc,
//resize image so that neither width nor height is > 150, tben recenter
onClipEvent(load) {
var maxWidth = 150;
var maxHeight = 150;
if (this._width > maxWidth || this._height > maxHeight) {
var scaleFactor = this._width > this._height ? maxWidth / this._width : maxHeight / this._height;
this._width = Math.floor (this._width * scaleFactor);
this._height = Math.floor (this._height * scaleFactor);
this._x = 85 - (this._width/2);
this._y = 90 - (this._height/2);
//display gallerywm_mc at bottom of resized image
var gallerywm = _parent.gallerywm_mc;
gallerywm._x = this._x;
gallerywm._y = this._y + this._height - 20;
gallerywm._width = this._width;
gallerywm._height = Math.floor (gallerywm._height * this._width /150);
//hide boundingbox_mc if image is portrait orientation
if (this._height == 150) {
_parent.boundingbox_mc._visible= false;
}
//hide imagepreloader_mc
_parent.imagepreload_mc._visible= false;
}
}

View Replies !    View Related
Need Basic Lesson On 'on ClipEvent ()'
Ok, I've been told a couple of times to use the on ClipEvent() actionscript to do something.

However, if I put it in the main timeline or the movieclip's timeline, it refuses when I export.

Where do you actually put the code?

View Replies !    View Related
ClipEvent For Dynamic Clip
Ok.. I have a dynamic xml menu systmem that I have hacked around from some script that I got from somewhere. I'm trying to convert it to a drop down menu system. I made it so that i you can click to open and click to close each menu but I want it on mouse over. The trouble is the usual way of solving this is...

onClipEvent (enterFrame) {
if (this.hitTest(_root._xmouse, _root._ymouse, true)) {
this.gotoAndStop("over");
} else {
this.gotoAndStop("off");
}
}

but as my menu items are all scripted on to the stage where would I put this code??

View Replies !    View Related
[F8] ClipEvent Handlers Question
I don't consider myself really good at anything. AS is one of those. I am not bad at it, having handwritten about 40,000 lines so far, but there is still so much that I don't truly understand.

Currently I am trying to figure out what is the useful difference between


Code:
onClipEvent(enterFrame){
and


Code:
onClipEvent(load){
I mean, I know the obvious differences, but as far as coding goes I am lost. depending on the need/use of the AS, if I use one and it doesn't work I use the other, but I don't know "why".

Can some one explain the "why"?

~MoN

View Replies !    View Related
Loading A Movie Into A MC Using Clipevent?
Code:
onClipEvent (enterFrame) {
if (_root._currentframe>=_root.thisFrame+1) {
loadMovie("BANNERS/01/01.swf", "this");
}
}
I have this on a mc, but I can't get it to load the file, it works on frame, and loads where I want it, but when I put it on the MC I want it to load into, it stops working, now I know it's some kindof syntax, but so far everything I've tried has failed.

Any ideas?

thanks in advance

View Replies !    View Related
Variable Value Not Passing To ClipEvent
Frame1:

ActionScript Code:
stop();loadText = new LoadVars();loadText.load("gallery.txt");loadText.onLoad = function(success) { _global.total = this.total; trace(_global.total); gotoAndStop(2);};

Frame2:

ActionScript Code:
stop();MovieClip.prototype.tot = total;MovieClip.prototype.i = tot/2;MovieClip.prototype.j = i;MovieClip.prototype.num = tot;


Attached on a mc (within a mc):

ActionScript Code:
onClipEvent (load) { this._visible = 0;}onClipEvent (enterFrame) { //CODE GENERAZIONE QUARDATI trace(tot); for (var i = 1; i<tot+1; i++) {  e = "foto"+i;  if (i%2 != 0) {   if (i != 1 && i != 2) {    yp = 0;    xp = _parent["foto"+String(i-2)]._x+68;   } else {    xp = 0;    yp = 0;   }  } else {   if (i != 1 && i != 2) {    yp = 68;    xp = _parent["foto"+String(i-2)]._x+68;   } else {    yp = 68;    xp = 0;   }  }  duplicateMovieClip(_parent.foto, e, i);  _parent[e]._x = xp;  _parent[e]._y = yp;  _parent[e].img._xscale = 64;  _parent[e].img._yscale = 64;  _parent[e].foto.n.text = i;  _parent[e].dataa = dataa[i];  _parent[e].link = link[i]; }}


What it does (should do) basicaly is duplicate the mc foto for the value of tot.
The txt file is loaded properly and it does trace the correct value for total and tot but it doesn't duplicate the movie.
If instead of

ActionScript Code:
MovieClip.prototype.tot = total;

I write

ActionScript Code:
MovieClip.prototype.tot = 10;

Everything works fine.
Any idea why if tot and total trace the right value, the duplicateMovieClip won't work???

View Replies !    View Related
On ClipEvent With Movie Clip....help
Hey, I have a movie clip that has its own timeline animation. When the mouse is clicked on the movie clip, the animation starts and then is removed. So, I can do this easily when the movie clip is dragged on the stage, I click on it and add the on clipEvent(mouseDown) script.
But when the movie plays, I need to have the mc generate on screen a bunch of times. When its in the library, it doesnt have the on clipEvent(mouseDown) script and I cant figure out how to add the script to the mc in edit mode when its in the library, I keep getting errors.
Any ideas?

View Replies !    View Related
Stop ClipEvent (enter Frame)
Here is my code:

onClipEvent(load) {
badPeanutSpeed=random(4);
function badPeanutReset() {
this._x=random(400);
this._y=0;
this._visible=true;
}
badPeanutReset();
}


onClipEvent(enterFrame){
this._y = _y+badPeanutSpeed+3;
if(this._y >= 300){
badPeanutReset();

basically when this MC loads its giving it a random _x position. the enter frame is telling the MC to fall vertically at a random speed and when it gets the the bottom of my stage to reset to the top with a new random _x position. Its basically a loop. I need to know how to stop it based on other script elsewhere. I need to know how to manipulate the data to either stop the clipEvent (enterFrame) or something. Please help.

View Replies !    View Related
Help Converting Code From A Mc Clipevent To An Array...
im creating a side scrolling game, but instead of a space ship and enemy ships, i have a guy dodging a flower, a cat, and a perfume bottle... so far everything is working fine. the following code example is what i have on the flower, cat and perfume bottle. they are all set up onClip events with random locations and hit test.. HERE THE WORKING CODE....


onClipEvent (load) {
function reset(){
this._x = random(600)+1500;
this._y = random(500)+100;
enemySpeed = 10;
this.gotoAndStop(1);
}
reset();
}


onClipEvent (enterFrame) {
this._x -= enemySpeed;
if (this._x <- 100) {
reset();

}
if (this.hitTest(_level0.guy.hitTarg)) {
_level0.lives--;
_level0.counterDist.stop();
trace("you hit the flowers");
}
lives();
}


what i want to do is consolidate this code(x3 becasue this code example was only from the flower mc) into an array...AM I ON THE RIGHT TRACK HERE???? i need all the randomness and hit.test incorporated into the array..


var numEnemy = ["flower", "perfume", "cat"];

for (var i:Number = 0; i < numEnemy.length; i++) {
flower.duplicateMovieClip( "flower", "flower" + i, i + 100);
perfume.duplicateMovieClip( "perfume", "perfume" + i, i + 500);
cat.duplicateMovieClip( "cat", "cat" + i, i + 1000);
}

View Replies !    View Related
Detect Mouse Click Within Another Clipevent
Hello,

I'm using the following script on a movie clip to produce an animated drop down menu:

onClipEvent (enterFrame) {
if (this.hitTest(_root._xmouse, _root._ymouse, true)) {
this.nextFrame();
} else {
this.prevFrame();
}
}

This works such that when the mouse is within the boundaries of the movie clip, the menu activates forward and when the mouse leaves the boundaries, the menu activates back to initial state. I'm wondering how to amend this code so that a mouseclick within the movie clip will produce the same effect as leaving the boundaries of the movie.

Example:
movie clip is a menu dropdown...
- user highlights a menu item button within drop down
- user clicks on menu item
- drop down menu scrolls back up even though mouse is still within boundaries

Link to example:
http://www.davegk.com/dropdownmenu.html
source:
http://www.davegk.com/dropdownmenu.fla

Thanks!
David

View Replies !    View Related
Changing Mc Name In A While Function
OK I can never figure this out, so that means I'm either going about it completely the wrong way, or it just can't be done yet...

I want to perform a gotoAndStop() on a series of movieclips that are sequentially numbered... I tried doing this, but it's not happy..

function moveMCframes() {
i=1;
while(i<=10) {
xScene = (_root.myMovie.mySubMovie + i)
xScene.gotoAndStop(2)
i++;
}
}


I suspect that this is pretty easy, but as I'm not a full-time coder *L* I tend to bang my head against the wall more often than not...

View Replies !    View Related
Changing The Function
The following code is what I use for creating a menu of links to add to my website. currently it opens a new window and loads a website into that window. An example of this can be found on one of the first sites I ever did www.zephn.com/trpa on the bottom left of the main page.

I want to change the function to load a movieclip into a container i have set up in my main movie. I created a little site for my video game friends at www.zephn.com/wowmovies and want to use the menu this code relates to.

I tried subsituting the openwinCentre command with

loadmovie (siteToLoad,"imagelist");

This did not work. Am I tackling this from the wrong point of view?




var menuItems = ["The Gates of AQ"];

var siteList = ["aq1.swf"];

for (i=0; i<menuItems.length; i++) {
var mc = container.dynamicButton.duplicateMovieClip("button "+i, i);
mc.menuLabel.text = menuItems[i];
mc._y = i*(mc._height-1);
mc.siteToLoad = siteList[i];
mc.actualButton.onPress = function() {
openWinCentre(this._parent.siteToLoad, "TRPA", 780, 640, 1, 1, 1, 1, 1, 1, 1);
};
}

View Replies !    View Related
[Flash MX 2004] Daft ClipEvent + If Statement Problem :(
hi, ive been playin around again not got stuck on a simple clipEvent + if statement bit, its really quite daft, but why it doesnt work is beyond me?

Theres an MC (lecafe) with a button in on the main stage, the button is in an MC itself (logons) with two different states (on-in + off-in). when the clip hits a certain frame the status changes to off. so once the status has changed, the button in the logons MC should change 2 the 2nd state.

if u dont quite get what i mean, check it outhere

After the lil log in movie the icon fades and returns (top left corner) once u click it again the text in the window should then say "Log Off?". - But it dont :'(


Code:
onClipEvent(enterFrame) {
if(_root.status.equals("on")) {
_root.lecafe.logons.gotoAndStop("on-in");
}
else if(_root.status.equals("off")) {
_root.lecafe.logons.gotoAndStop("off-in");
}
}


what i have at the moment (above) works for the first test but not the second. ive tried using different methods such as


Code:
_root.status = "on";


and different types of if's. im not sure if when u use an 'else if' u have to include an 'else' to catch the exceptions.

Ive tried and tried n finally decided to come worship at the holy Flash Kit Shrine and ask for your wisdom. can anyone help?

View Replies !    View Related
Animating A Clip Without Attaching Logic To The ClipEvent OnEnterframe
I need to create a custom scrollbar dynamically and am stuck because usually when I script motion for movieClips I do this:

onClipEvent(enterFrame){

---animation code here---


}

Can anyone show me a few lines of code that are not attached to a movieClips enterFrame Handler. That simply moves a movieClip accross the stage.

For example code that could go on frame 1 or in a .as class file.

Thanks.

View Replies !    View Related
Function With Changing Variable
hi

it is to late to change this in my project right now, but for future project i'd like to know the following:

i have a button, which should change several movie clips. so i had the button change a variable. the other mcs then check the variable and do whatever procedure is "attached" to that state of the variable. so most of the time if i push a button the following happens: the mcs are doing something with the old state of the variable, then the variable changes and they do something with the new state. my "problem" with that is, that i can't make one funtion out of it, because in the middle of the process the variable is changed to the one specific number that only that button will it give it. so i have to do a function for what happens before the change of the varibale, then change the variable, then have another function for what happens after the change.

is there a solution to that problem?

thanks
Robert

View Replies !    View Related
Changing The Array In The Function
I have an online gallery i've built.. and have run into a snag. My function called "setCatButtons" passes a variable called "catagoryArray" and assigns it to the variable in the button that identifies which array to use.

i will have several arrays.. illustrationItems, designItems, webItems
each containing the name of jpg to load.


my button coding function works great like this....


function setCatButtons():Void {
catagory.btn2.onRelease = function():Void {
imageLoader.loadClip("images/" + illustrationItems[1] + ".jpg",imageContainer_MC.imageContainer);
}
}



however, if i use this function and insert a variable to select which array to use, it will not work.

setCatButtons("illustrationItems");

function setCatButtons(catagoryArray:String):Void {
catagory.btn1.onRelease = function():Void {
i=0;
imageLoader.loadClip("images/" + catagoryArray[1] + ".jpg",imageContainer_MC.imageContainer);
}

i tried using "eval(catagoryArray[1]) " which will display the selected array if i dont use "[#]" ,but wont evaluate which item in the array to use. sooo.. i am stuck. I've tried setting "catargoryArray:Array" as well in the function.

any ideas?

View Replies !    View Related
Changing The Function On The Second Click
This is probably stupidly easy, but i cant seem to do it anyway.

I've got a button that i'm using with the telltarget command to make a movieclip play a few frames when clicked. What i want it to do is go to a DIFFERENT part of the movie clip when it is clicked a second time.

I keep trying to find this in tutorials and have failed miserably. Any help is much appreciated!

View Replies !    View Related
Changing The Scope Of A Function.
Here is the script:


ActionScript Code:
function delay(pFunc:Function):Void {    this.onEnterFrame = function() {        pFunc(param);        delete this.onEnterFrame;    };}delay(test, 1);function test():Void {    trace(this); //traces "[object Object]"}

It's stripped down to reproduce my issue.

I want to change the scope of the event, so that when test is called, it traces "_level0 instead of "[object Object". I was thinking Delegate.create() would be the way to go, but I can't figure out how to get that to work within the scope of this function. I know what is happening, I'm just not sure how to fix it.

If I could just do it in AS3 it wouldn't be an issue, but it's AS2, c'est la vie.

View Replies !    View Related
Changing The Function On The Second Click
This is probably stupidly easy, but i cant seem to do it anyway.

I've got a button that i'm using with the telltarget command to make a movieclip play a few frames when clicked. What i want it to do is go to a DIFFERENT part of the movie clip when it is clicked a second time.

I keep trying to find this in tutorials and have failed miserably. Any help is much appreciated!

View Replies !    View Related
AS3 - Call A Function Whenever The .y Is Changing
Hi people,

well, I'm new to AS3 and I'm just witting my first class which is a scrollbar. I have faced a problem that till now I have found 2 solutions for that but I wanna try and see if there's anything better to be done about it or not.

in short, I want to update the y position of a MovieClip according to the position of the scroller. I know that I can use Timer class or ENTER_FRAME but these two classes are bugging me a bit, because they both give me a feeling that they are eating CPU usage!

Am I correct? does the event ENTER_FRAME eat my CPU? as I'm working on a quite big project and I don't want to kill the cpu so early!

the possible third solution I am thinking of is to somehow call a function as soon as we are dragging the scroller and that's it instead of infinitely listening for the .y position of the scroller...

Am I making sense?! Please do ask for more explanation if this is not clear.

Thanks,
Hadi

View Replies !    View Related
[as] Changing A Mediadisplay Function
Here's the problem:

The stupid mediadisplay object messes up whenever you call the setMedia function on it twice (to load the same file).

How can I change the setMedia function for every dynamic instance of the mediadisplay object in my project?

I would like for it to read something like this:

new mediadisplay.setMedia function (file, type) {

if mediadisplay.bytesLoaded = -1 {

mediadisplay.setMedia(file, type)

} else {

do ABSOFREAKINGLUTELY nothing

}

}


any suggestions?

View Replies !    View Related
Varibales Changing Using LC To Run A Function...
How would i go about , having a function called when a variable was changed by using local connection from another swf. My menuing system I am trying to set up has "n" main buttons in it. When one of those buttons is clicked it changes a variable in the second swf which in turn rebuilds that menu using ASP/XML. I thought I could use a watch to check the variable but after some reading on watchs maybe it is not the best way. I saw in some peoples posts using setters and getters might be the best way but i not really have a firm grasp on that concept.

View Replies !    View Related
Moving An Mc With A Function, Changing Variables...
I'm a newbie, but this is perhaps not a newbie question.
I'm trying to get an mc to move (slide smoothly instead of just appearing in another location) under a button when mouse rolls over, and to go back to it's original position when mouse rolls out.
Here's what I did:

On frame 1 of timeline:

stop ();
var hit1

function moveClip (buttonLocation) {
//if mouse is to the left of the clip
if (_root.clip._x < _xmouse) {
do {
//move it to the right
_root.clip.x + 5
//until it reaches the button
} while (_root.clip.x < buttonLocation);

//and the contrary...
} else {
do {
_root.clip.x - 5
} while (_root.clip.x > buttonLocation);
}
}

On the button (an mc) I put
onClipEvent (mouseMove) {
if (this.hitTest(_root._xMouse, _root._yMouse)) {
_root.hit1 = yes
}
}

I called the function from many places (starting with the clip and an onclipEvent (enterframe)) without any luck.

Moreover, I tried testing the if statement of the button with a regular action, such as "if hit1 equals yes then do whatever", and it doesn't recognize the change in variable hit1.
I understand that this code is not finished, I would need to get the clip to go back to it's original position on rollout, but I can't keep going if I can't get this simple part to work!!
Any help is greatly appreciated,
Mike

View Replies !    View Related
Changing The Tint Settings With A Function?
I have a simple movie with about 10 frames, each has a stop action and I have a forward/previous frame style navigation.

I would like to know how to make the tint of a movie clip in each frame change when its frame is hit. Needs a function of some kind in the mian timeline on that frame, but not sure how to do it? Im after a smooth transition from whatever colour it was before, to the new colour settings

Any ideas?

Thanks

View Replies !    View Related
[SIMPLE] Changing A Function Parameter [Different From Last]
I need to change a function parameter, but I don't want to actually call the function itself, it is to 'fool' the function. How do I do that?

if I have a function like this one, how can I change [bname] without acutally calling the function?:

code:
selectMe = function(bname:String) {
if ([bname].swf==mc.swf) {
trace('use existing loaded clip.');
}
}

View Replies !    View Related
[F8] Changing Code To Function Breaks It
Hi there, I'm trying to make this piece of code (that takes a jpg/gif turns it into bitmap data, and tiles it BEHIND everything else) into a function, so I can call it with different parameters (such as img url, description etc.).

This is the code inline, that works perfectly:

code:
initialLoad("loading wallpaper...");
img = "./images/bg.gif"
this.createEmptyMovieClip("tile_mc", this.getNextHighestDepth());
//trace(this.getNextHighestDepth());
loader = new MovieClipLoader()
loader.addListener(this)
loader.loadClip(img, _root.tile_mc)

function fillBG() {
this.beginBitmapFill(myBitmap);
this.moveTo(0,0);
this.lineTo(Stage.width,0);
this.lineTo(Stage.width,Stage.height);
this.lineTo(0,Stage.height);
this.lineTo(0,0);
this.endFill();
}

function onLoadInit() {
updateLoad("wallpaper loaded.");
myBitmap = new BitmapData(tile_mc._width, tile_mc._height,true,0x00FFFFFF)
myBitmap.draw(tile_mc)
tile_mc.removeMovieClip()
fillBG();
}

function onLoadError() {
tile_mc.removeMovieClip()
}

fillBG();

var stageL:Object = new Object();
stageL.onResize = function() { fillBG(); }
Stage.addListener(stageL);


Now this code is my attempt at modifying it to a function (just adding function x(), and closing {, then calling it)

code:
function loadTile() {
initialLoad("loading wallpaper..."); //changes text for preloader
img = "./images/bg.gif" //url to image
this.createEmptyMovieClip("tile_mc", this.getNextHighestDepth());
//trace(this.getNextHighestDepth());
loader = new MovieClipLoader()
loader.addListener(this)
loader.loadClip(img, _root.tile_mc)

function fillBG() {
this.beginBitmapFill(myBitmap); //this code tiles the bitmap
this.moveTo(0,0);
this.lineTo(Stage.width,0);
this.lineTo(Stage.width,Stage.height);
this.lineTo(0,Stage.height);
this.lineTo(0,0);
this.endFill();
}

function onLoadInit() {
updateLoad("wallpaper loaded.");
myBitmap = new BitmapData(tile_mc._width, tile_mc._height,true,0x00FFFFFF)
myBitmap.draw(tile_mc)
tile_mc.removeMovieClip()
fillBG();
}

function onLoadError() {
tile_mc.removeMovieClip()
}

fillBG();

var stageL:Object = new Object(); //this is a listener for when it resizes
stageL.onResize = function() { fillBG(); }
Stage.addListener(stageL);
}

loadTile();


Now the first code works perfectly, the second loads the bitmap ABOVE everything else, and doesn't tile.

I can't figure out what it is - any ideas?

Many thanks, look forward to some help - all help so far has been great! love you ALL!

View Replies !    View Related
How Can I Add Button Function To Depth Changing Mcs?
i am using this code to change the depth / bring forward button by onrollover:


Code:
depth=mc4.getDepth()
s2a.onRollOver=s3a.onRollOver=s4a.onRollOver=s5a.onRollOver=function(){
depth++
this.swapDepths(depth)
txt1.text=this.getDepth()
}
but this code disables the 'normal' button codes.
how can i add onPress or onRollover functions to the buttons/mcs by expanding this code?

View Replies !    View Related
Changing Dynamic Text From Function
Hello,

I'm trying to change the text in a dynamic text box (which itself I've created by createTextField through actionscript), and I'm trying to do it from within a function. However, I can't seem to do it!

Basically, I've go this bit which creates the text box:


_root.createTextField("mytext",105,125,428,300,100 );
mytext.text = "TEXT DISPLAYED";

myTextFormat = new TextFormat();
myTextFormat.font = "Arial";
myTextFormat.size = 11;
myTextFormat.color = 0x999999;
myTextFormat.align = "right";

mytext.setTextFormat(myTextFormat);

textInstance.setTextFormat(myTextFormat);




and then later on I have a function which fades in an image when a button is pressed:



buttons_mc4.four_mc.onRelease = function() {
new Tween (container_mc,"_alpha",Strong.easeOut,100,0,20,fal se).onMotionFinished = function(){
container_mc.loadMovie("../images/4.jpg");

fadeIn();
}
}



I tried putting this in to change the text in the dynamic text box but it didn't work:



buttons_mc4.four_mc.onRelease = function() {
new Tween (container_mc,"_alpha",Strong.easeOut,100,0,20,fal se).onMotionFinished = function(){
container_mc.loadMovie("../images/4.jpg");

fadeIn();
}
mytext.text = "TEXT DISPLAYED";
}


any ideas what I'm doing wrong?

All suggestions greatly appreciated! Cheers.

View Replies !    View Related
Changing Math.random Function
Hello,

Have anyone tried to modify the Math.random function to return a static value?
Or where the functions libraries are located on my PC?

Thank you.

View Replies !    View Related
Changing Property Values From Within A Function
I'm wondering how I can change a property of an instance from within a function inside a method. I have some code here... Basically I just need to set _lynn_idle to false when a tween is occuring and _lynn_idle to true when the tween is finished. Unfortunately I can't seem to simply set it to false or true inside these listener functions like I'm able to anywhere else (seems the variable is only local to the function when I need it to access the variable associated with the instance). Any help is much appreciated.







Attach Code

private var _lynn_idle:Boolean;

public function moveToTile(tilecoord:Array):Void {
// move lynn with a tween
var startx:Number = _lynnmc._x;
var starty:Number = _lynnmc._y;
var endx:Number = (30*tilecoord[0])+(30*tilecoord[1]);
var endy:Number = 15*(tilecoord[0]-tilecoord[1]);
// determine how long the tween should take
var movedur:Number = 12;

var moveListener:Object = new Object();
moveListener.onMotionChanged = function():Void {
_lynn_idle = false;
// check depths of props and swap

}
moveListener.onMotionFinished = function():Void {
_lynn_idle = true;
// rebuild floor
_lynn_pos = tilecoord;
_global.room.newFloor();
// doAc() to props
}

var moveLynnx:Tween = new Tween(_lynnmc, "_x", Regular.easeInOut, startx, endx, movedur, false);
var moveLynny:Tween = new Tween(_lynnmc, "_y", Regular.easeInOut, starty, endy, movedur, false);

moveLynnx.addListener(moveListener);
}

View Replies !    View Related
Changing Property Values From Within A Function
I'm wondering how I can change a property of an instance from within a function inside a method. I have some code here... Basically I just need to set _lynn_idle to false when a tween is occuring and _lynn_idle to true when the tween is finished. Unfortunately I can't seem to simply set it to false or true inside these listener functions like I'm able to anywhere else (seems the variable is only local to the function when I need it to access the variable associated with the instance). Any help is much appreciated.







Attach Code

private var _lynn_idle:Boolean;

public function moveToTile(tilecoord:Array):Void {
// move lynn with a tween
var startx:Number = _lynnmc._x;
var starty:Number = _lynnmc._y;
var endx:Number = (30*tilecoord[0])+(30*tilecoord[1]);
var endy:Number = 15*(tilecoord[0]-tilecoord[1]);
// determine how long the tween should take
var movedur:Number = 12;

var moveListener:Object = new Object();
moveListener.onMotionChanged = function():Void {
_lynn_idle = false;
// check depths of props and swap

}
moveListener.onMotionFinished = function():Void {
_lynn_idle = true;
// rebuild floor
_lynn_pos = tilecoord;
_global.room.newFloor();
// doAc() to props
}

var moveLynnx:Tween = new Tween(_lynnmc, "_x", Regular.easeInOut, startx, endx, movedur, false);
var moveLynny:Tween = new Tween(_lynnmc, "_y", Regular.easeInOut, starty, endy, movedur, false);

moveLynnx.addListener(moveListener);
}

View Replies !    View Related
Changing Fonts In Typewriter Function
Hi everyone,

Does anybody know where i can find tutorial to build my own typewriter function, insert html text, changing fonts etc...

Regards,

Jerome

View Replies !    View Related
Newb Problem Counting MouseMoves (as ClipEvent To Load Random Swfs)
help required please - have tried diy through searching threads but can't do it by myself !

i have an empty movie clip (instance name random_fink) on the stage into which i am randomly loading swfs from a bank of 10 (named fink_1, fink_2 etc) using


ActionScript Code:
onClipEvent(mouseMove) {

var num_finks = 10
var finkName = "fink_" + Math.floor ( Math.random( ) * num_finks);

_root.random_fink.loadMovie ( "fink_" + Math.floor ( Math.random( ) *
num_finks);

}

at the moment this happens in scene1 - i want the user to move the mouse ten times ie ten random swfs to run, before the movie goes to the next scene

i think this is quite complicated and i'm no a.s. genius - just self taught as i go along - HELP !!!

View Replies !    View Related
Changing Button Function On Different Parts Of Timeline
Hi there, Im fairly new to AS 3.0, ive been working on a website and have some movie clip buttons on the side of the page, whenm these buttons are clicked they fade out then a graphic fades in and the top of hte page with the same text name as the button that was pressed, then when another button is pressed the text graphic fades out, the button fades back in and the new button that has been pressed fades out and the text from that button fades in at the top of the page in a graphic.

I have probably gone about this in a backwards way for a noob. I have I have created the fade out and graphic fade in for each button along the timeline and labelled each frame where it starts, I have then created a fade out for each other button and then a gotoAndPlay to do the fade out then go to and play for the selected fade in the the pressed button.


So I have actionscript for each section of the timeline for the buttons that are visible to carry out different functions, so the play head skips back and forth and the functions of the buttons changes depending on where the play head is.

This is half working but when some buttons are pressed wrong rolout scenes are played, I have checked all spelling and made sure all gotoAndPlay frame names are correct and they are,

which leads me to believe the action script is been disabled once it has been played once?

Is it possible to change the function of a button puttins AS in diffent frames on the timeline which are navigated back and forth?

I had this working in AS2, when you could put script directly onto symbols, but cant get it going when scipt uis put into frames on timeline..

sorry for the essay, I hope it makes some sense, any help appreciated I have been wokring on it for agesss!

Thanks

View Replies !    View Related
Changing Variable (dataType Function) With A ComboBox
Platform : Flash CS3, AS3

Hi, I hope this will be an easy problem for some of you.

I have a variable (easeType) sat in a Class called dragClip
it's set within the class like so;


Code:
public var easeType:Function = Elastic.easeOut;
this variable changes the type of easing of the class when it uses a tweening method.


I want to use a comboBox on the Stage to change the value of this variable, so that the class eases in the way specified by the comboBox. I have it populated with options like Bounce.easeOut and Strong.easeOut

On the timeline, I have this code;


Code:
function changeHandler(e:Event):void {
var cb:ComboBox = e.currentTarget as ComboBox;
var fn:Function = getDefinitionByName(cb.selectedLabel] as Function ;
dragClip.easeType = fn;
}

easePicker.addEventListener(Event.CHANGE, changeHandler);
Unfortunately, when I select anything in the comboBox, I get this error;


Quote:




ReferenceError: Error #1065: Variable easeOut is not defined.
at global/flash.utils::getDefinitionByName()




I assume the problem is because of the dot between (for example) Strong and easeOut but I don't really know where to go from here.

View Replies !    View Related
Changing A Buttons Function Based On Dynamic Text
Hi, im new to the forum, and semi-new at flash, i have experience doing the 'pretty' side of flash, but little in the action script side, and was wondering if anyone could help me.

What i am trying to do, is inside a quiz have a 'next' button, which directs the user to either the next frame or a specific scene based on the response to an answer the user got for the last question.

To explain in a more simplified fashion, if there is a question such as 'The sky is blue' True/False (to use on of the examples from macromedia) if they get it correct, the next button will take them to scene 2 frame 1, if they get it wrong the button will take them to the next frame in the same scene.

Got any ideas of how i can achieve this?

Thanks, Sam

View Replies !    View Related
AS2 - Changing IFrame URL From Flash By Calling A JS Function With ActionScript
Guys;
For over a week now, I've bee struggling with this problem for my current project, which involves many more challenges besides this one, and is soon to reach the deadline. Needless to say, I could really, really use your help.
Here, is a simple HTML page with an iFrame and a button that changes the source URL of that iFrame. The following is the page source, which can also be viewed from browser - simple as that.

HTML Code:
<head>
<script type="text/javascript">
function changeURL()
{
document.getElementById('myFrame').src='http://www.altavista.com/';
}
</script>
</head>
<iframe src="http://www.google.com/" width="800" height="400" id="myFrame"></iframe>
<input type="button" value="CHANGE URL" onclick="changeURL()"/>
What I need though, is to be able to do the same thing but with an SWF button instead, so that the changeURL function is called from within Flash.

As I mentioned, I spent tons of hours looking all over the web for a working(!) solution. This would include most tutorial sites and message boards you know (in addition to the official documentation). The thing is that my AS skills can be described as intermediate at best, so it's very easy for me to get confused. Some of the unofficial material I found was in AS3, occasionally without any mention of it. Other guides would be a bit dated and fail to take in account Flash Player security related patches/updates/changes, etc. As for the forums, I either get more and more lesson links, or explanations that are not thorough enough for me to comprehend. The guys would, for instance neglect to mention the exact classes that need to be imported, or they'd explain the syntax in a formulaic fashion, as opposed to using plain fictitious or actual examples, you know, quotations, wild cards, in other words the kind of things that imply to pros automatically, but would easily confuse n00bs like me. This breeds even more questions in my head, which I'm too embarrassed to ask more of, knowing how busy everybody is, etc. Some people have info in their blogs, but those are high level users and their examples are so complex that I feel lost.
The reason why I'm telling you all this is because it's all come down to me having to ask someone to put some primitive example for me, or at least explain it to me in greater detail; not because I'm lazy to do it myself, but because I'm really lost on this one and pressed for time.
I'm sure my request is a peace of cake for someone who's already done it. It can't possibly be anything more than a few lines of code; just a small rectangle that calls that function onRelease.
Again, your input would be greatly appreciated. Hope to hear from you soon.

PS. I can make use of swfobject.js. Also, if possible, I'd like to pass the URL string as an argument from Flash, or course.

View Replies !    View Related
Changing Global Variable From Inside A Function And Maintaining Access To It.
Hello,

I am trying to set the value of a global variable from inside a function.

here is my code:
**************************
//set movie globals
_global.startpane;

//fetch preferences
prefData = new LoadVars();
prefData.load("prefs.txt");
prefData.onLoad = function(success) {
_global.startpane = prefData.start;
};

trace(_global.startpane);
*************************

When I test this the output screen says "undefined".
It works perfectly when I put the trace call INSIDE the function call but I need to be able to change the global variable and then access it from anywhere.

Can anyone help?

View Replies !    View Related
Changing The Function Of A Button Depending On Previous Button Press
Hi all,

this problem has been stressing me out all day! (its probably extremely simple, but i can't get my head round it)

I was wondering if anyone can help me, I'm loading in 5 jpegs from an external file using "loadMovie" and i have 5 corresponding buttons (1-5) to load them with.

I want to change the jpeg the button loads in depending whether a separate navigation button has been pressed -

i.e.

navigation buttons:

-motorbike pics
-car pics
-lorry pics

If a user clicked on "car pics" then the loading buttons 1 to 5 would load "car1.jpg", "car2.jpg" and so on...

similarly if the user clicked on "lorry pics", the same loading buttons 1 to 5 would load "lorry1.jpg" and "lorry2.jpg"

any help and code snippets would be greatly appreciated!

Thankyou!

View Replies !    View Related
Changing Height Of Movie Clip Without Changing Width
Im using flash MX, and i needed to know if it was possible to change the height of a movie clip without changing the width of it. i have a 1px wide line, and i want to change the height of it, but i want to keep it 1px wide. is it possible to do this without having to redraw it everytime i want to change it?

View Replies !    View Related
Copyright © 2005-08 www.BigResource.com, All rights reserved