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




OnMouseUp Scope Problem.



Hello.

I am new to Flash and ActionScript, I hope my question is easy for you guys to answer, I don't want to take too much time from you.

The following code is intended to trace out when the user clicks over the created MovieClip but not when you click outside the MovieClip, that was the intention. My understanding was that by attaching the onMouseUp function to the MovieClip my_mc, it will only takes place when the user click over that MovieClip. At least that's the impresion I got from Macromedia documentation since they're attaching the event function to a MovieClip.


Code:
//Create a MovieClip on stage.
_root.createEmptyMovieClip("Square", _root.getNextHighestDepth());
var my_mc:MovieClip = Square;
my_mc.beginFill(0x345678, 100);
my_mc.moveTo(0, 0);
my_mc.lineTo(0, 100);
my_mc.lineTo(100, 100);
my_mc.lineTo(100, 0);
my_mc.endFill();

//Control its onMouseUp event.
theMovie.onMouseUp = function()
{
trace("onMouseUp called from theMovie");
}
Thank you for your help.

Andrea.



ActionScript.org Forums > ActionScript Forums Group > ActionScript 2.0
Posted on: 02-02-2007, 09:26 PM


View Complete Forum Thread with Replies

See Related Forum Messages: Follow the Links Below to View Complete Thread

Obj.onMouseUp
Hi!

I am using the following script to return to an input box (inp_txt) when the stage is clicked:

obj = {};
obj.onMouseUp = function(){
Selection.setFocus(inp_txt);
}
Mouse.addListener(obj);

However, this is not working when I am in a separate scene. When I am in a separate scene, problems occur as the code is redirected to a second input area (inp_txt2).

I understand we are to never target a scene == To change scenes I have created a frame label on the first frame of the desired scene and targeted that.

So is there a reference script to determine in which scene I am to set focus to the chosen input text box?

PS Thanks AMD for your previous posts!

Thanks

Strange Act Of 'onMouseUp'
Hi all,
When I create my own class extending the MovieClip class,
I used the 'onMouseUp' method to invoke some behaviour of my class.

When finished my own MovieClip class I attached a some couple of
instances to the _root. On testing something seemed to go wrong.
As soon as I released my mousebutton on an instance, all the other instances where affected too.

So I debugged my class by some tracing actions and found out that
the method 'onMouseUp' returned each of the instances, not the only one I released my mouse on. The method looked like this:

Code:
function onMouseUp() : Void
{
trace( this );
}
I started thinking and thought of the following reason:

1. All instances where attched to _root ( a _parent MovieClip )
2. Other methods like 'onRelease' only returned the right instance


Conclusion: onMouseUp is invoked if the mouse goes up a
MovieClip and executes its code equal to the number of instances
attached to it, because the mouse is going up on these instances too!

OnMouseUp > On Release Outside?
Hi,

if I have this code:

code:
mousecontroll.onMouseUp = function() {
//trace("release");
_root.pageDragged = false;
if(flip) {
flipOK = false;
if(sx<0 && pages._xmouse>0) flipOK = true;
if(sx>0 && pages._xmouse<0) flipOK = true;
trace(flipOK);
flipOff = true;
flip = false;
}
//if dragged, release it!
}


Is there any way to add something that the function is also called when the mouse is release outside the movie?

Now when you drag out the movie the page get's stuck at you mouse.
I tried adding a blank button with on (releaseOutside) but that gives a flash of the book in this movie.

thanks

OnMouseUp- Only In Hit Area
I have one movie clip button with _up, _over, _down and hit setup properly. I created another movie clip that I want to be displayed when the user clicks on the movie clip button. It kinda works but it works everywhere you click on the screen not only within the "hit" area of the movie clip button.


Code:
handmc.onRollOver = function() {
handmc.play()
}

handmc.onMouseUp = function() {
handinfo.play()
}

OnMouseUp Returning Name?
Hi guys,
I have a bunch of buttons that I want to have do the same thing; pass their instance names to a function that will advanced the play head appropriately. To avoid having to write a ton of .onRelease functions, I'm trying to find a way that I can have a symbol return it's name if the cursor is over it when clicked. I vaguely remember that one of the mouse events would do this by default, passing it through a 'me' type placeholder.

Something to this effect:
onMouseUp= function(mySymbol) {
trace(mySymbol._name);
}

Am I way off? It's seems like there should be an easy way to do what I'm talking about.
Thanks.

Using OnMouseDown OnMouseUp
i wrote a function that attaches a MC that is dragged and tests a hittest for a new location. and it almost works the way i want.but can any bodey explain to me why
only _root.mouseDown works and targetClipbtn.mouseDown doesnt?
and why when i add the second part of the code _root.onMouseUp nothing works?
(i put all the code....)

Code:
function rope() {
//creating and attaching an mc(ropeBtn) to it in order to drag it
this.createEmptyMovieClip("targetClipbtn", 1);
this.targetClipbtn._x = 143.45;
this.targetClipbtn._y = 83.5;
this.targetClipbtn.attachMovie("ropeBtn", "ropeBtn11", 1);
//finding th x and y of the mouse and compareing it to my MC with(hitTest)and start dragging
_root.onMouseDown = function() {
mxx = _xmouse;
my = _ymouse;
if (this.targetClipbtn.hitTest(mxx, my, true)) {
this.targetClipbtn.startDrag();
//comparing with the new location
onMouseMove = function () {
if (this.targetClipbtn.hitTest(243, 127.25, true)) {
this.targetClipbtn.removeMovieClip();
}
};
}
};
}
rope();

Code:
_root.onMouseUp = function():Void {
delete (_root.onMouseDown);
delete (_root.onMouseMove);
updateAfterEvent();
};

TextField And OnMouseUp
Im trying to run a function when the mouse button is released but only when the mouse pointer is inside a certain text field.

I tried this but it doesn't work.

Mouse.addListener(myTextField_txt);
myTextField_txt.onMouseUp = function(){myFunction()}

Any one have any ideas?

My OnMouseUp Shows Too Many Mc's
Check out this snippit of code. I don't quite know how to get what I want. I'm dynamically creating some resize handles around a textarea. What I need is for the onMouseDown event to show me which one of the 8 'Grabber' handles I'm on.

With this setup, it traces out all 8 every time the onMouseDown event fires. You can also see where I commented out an eventlistener, I couldn't seem to get it working.

Any Ideas? Thoughts? Comments?...

Thanks


Code:
for (var r = 1 ; r < 9 ; r++){
_root.attachMovie("GrabSquare" , ("Grabber-" + r) , currentDepth++);
var thisItem = eval("Grabber-" + r);
//thisItem.addEventListener("onRollOver", myGrabberMouseOverListener);
thisItem.onRollOver = function(){
Mouse.hide();
_root.attachMovie("MoverMouse" , "NewMouse" , currentDepth++);
startDrag(NewMouse, true);
}
thisItem.onRollOut = function(){
Mouse.show();
NewMouse.removeMovieClip();
stopDrag();
}
thisItem.onMouseDown = function(){
trace(this);
}
}

OnMouseUp Insanity Is This A BUG? Or Am I Doing S
I have this code:

MyThumbnail.prototype.onMouseUp = function() {
if (this.hitTest(bigFrame.nowLoading_mc)) {
bigFrame.album.showPhotoAt(this.depth, -120, -65);
} this.scaleOut();

}

// this is what the MouseUp event lauches

MyThumbnail.prototype.scaleOut = function() {
this.onEnterFrame = function() {
this._xscale -= 20;
this._yscale -= 20;
this._alpha -= 10;

if(this._xscale < 10) {
trace("LESS THAN 10");
removeMovieClip(this);
bigFrame.album.loadThumbnail();
}
}

}

The problem is that it fires all the time! No matter if it hits the
bigFrame MC!! Now here is the interesting thing...

If i remove "this.scaleOut();" from the onMouseUp event and add something
like a "trace" command, it will trace like it should, once the movie is
dropped over the bigFrame's nowLoading_mc.

Can anyone tell me why is this happening? And how can i fix it?

Thanks

An Interesting OnMouseUp Problem
Here's an interesting (and frustrating) prblem I've been having.

I've built a menu using a button class (aButton) and a menu class (aMenu) which builds from an xml feed using aButtons. I've gotten 90% of the code working and it works beautifully. The problem is whenever I click on a button it appears that all buttons are being triggered. The onMouseUp code is as follows:


PHP Code:




button.onMouseUp = function ( ) {
  trace ( "this: " + this );
  trace ( "this.url: " + this["url_" + this.id].text );
  //getURL ( this["url_" + this.id].text );
}






Both classes extend MovieClip but other than attaching other movieclips to it I haven't really taken advantage of it (I'm still learning how to).

Any help would be most appreciated and I can post other code as needed.

Thanks
<Seth />

Replacing This.onMouseUp = Function() {
Dear All,

I am very new to Flash and here is my problem. I am trying to create my own screensaver using some of Tarbel's code to create an array of pixels within a movie clip. Thats all fine.

However there is a function() that I would like to replace and this is the
this.onMouseUp:

this.onMouseUp = function() {
if (gridmade) {
// remove old grid
for (var n = 0; n<gridList.length; n++) {
gridList[n].doFadeOut();
}
gridmade = false;
makeGrid();
}
};
gridmade = false;
makeGrid();
stop();

I am trying to automate the regeneration of the grid but I have no idea how

Any help would be appreciated.

Peter

Automate This.onMouseup = Function()
Dear All,

I have posted the same question over on the newbies page but got no replies so hopefully some actionscript guru can help me with this.

I am using some of J. tarbell's opensource actionscript for a screensaver and the below function is called to reset the array so that flash rebuilds the pixel blocks.

Is there a way that I can call this automatically on (gridmade) ie the grid is automatically rebuilt after it is completed negating the user interaction (its a screensaver)

this.onMouseup = function() {
if (gridmade) {
for (var n = 0; n<gridList.length; n++) {
gridList[n].doFadeOut();
}
gridmade = false;
makeGrid();
}
};
gridmade = false;
makeGrid();
stop();

+++++++++Full Code++++++++++++++++++


var maxx = 16;
var maxy = 9;
var gridspace = 64;
function makeGrid() {
gridList = new Array();
gridSpot = new Array();
var depth = 0;
for (var x = 0; x<maxx; x++) {
for (var y = 0; y<maxy; y++) {
point = {x:x, y:y};
gridSpot.push(point);
}
}
this.onEnterFrame = function() {
buildGrid();
};
}
function buildGrid() {
var n = random(gridspot.length);
point = gridSpot[n];
gridSpot.splice(n, 1);
var nombre = "qr"+String(depth++);
var init = {_xoint.x*gridspace+gridspace/2, _yoint.y*gridspace+gridspace/2, _xscale:gridspace, _yscale:gridspace};
var neo = this.attachMovie("ColourSquare", nombre, depth, init);
var fr = 0;
var fr_mean = 0;
for (var k = 0; k<this.gridList.length; k++) {
if (neo.hitTest(this.gridList[k])) {
fr += this.gridList[k].shade._currentframe;
fr_mean++;
}
}
if (fr_mean == 0) {
neo.setFrameRandom();
} else {
fr = Math.round(fr/fr_mean);
neo.setFrame(fr);
}

gridList.push(neo);
if (gridspot.length == 0) {
delete this.onEnterFrame;
gridmade = true;
}
}

this.onMouseup = function() {
if (gridmade) {
for (var n = 0; n<gridList.length; n++) {
gridList[n].doFadeOut();
}
gridmade = false;
makeGrid();
}
};
gridmade = false;
makeGrid();
stop();

Mymovieclip.onMouseUp = Function()
Hi Guys,
I have just developed a simple xml photo gallery. Below is the code that I have used to generate the gallery:


Code:
var gallery = createEmptyMovieClip("galleryImage",0);
for (i=0; i<total; i++) {
cur_item = gallery.attachMovie("mainImage","spec"+i, i);
cur_item.loadMovie(thumb[i], "mainImage");
cur_item.onMouseUp = function() {
getURL(javascript:openWindow("products/"+id+"/"+image[i]));
};
}
I am having difficulties to make each movie clip generated into a button that will call the javascript button:


Code:
cur_item.onMouseUp = function() {
getURL(javascript:openWindow("products/"+id+"/"+image[i]));
};
What i want to do is to allow the user to click on the movie clip and it will call javascript and open the image in a html window. For some reason I can't get it to do anything. Am i using the correct code to do this?

Please advise

Much appreciated

Daniel

MX- Function Works OnMouseUp, Not With SetInterval
Hi,
seem to have something wrong with the following code.
a bug in my loop maybe
It draws curves between mc h12, using ctl mc as the control point to each of the mc's h0 to h9.
mc's are all dragable.
at the end I have two methods of calling the draw function. When testing I comment one or the other out. (only ever one active)

setInterval gives me a curve from h12 to 0,0
onMouseUp gives me all the curves to the h0 to 9 mc's

setInterval may be drawing 10 curves to 0,0, not sure.

code is in a mc on the root positioned at 0,0 that just contains the code

setInterval is the method I actually want to use

any idea whats going on
thanks mark

XStart = 100;
YStart = 0;
// attach the end point handles
for (i=0; i<10; i++) {
_root.attachMovie("squareHandle", "h" add i, i);
this["h" add i]._x = XStart;
this["h" add i]._y = YStart;
XStart = XStart - 10;
YStart = YStart + 10;
}
_root.attachMovie("squareHandle", "h12" , 12);
_root.attachMovie("roundHandle", "ctl", 11);
h12._x = 300;
h12._y = 100;
ctl._x = 188;
ctl._y = 225;
_root.createEmptyMovieClip("curve_mc", 13);
function draw() {
j = 0;
curve_mc.clear();
curve_mc.lineStyle(0, 0x000000);
for (j=0; j<10; j++) {
curve_mc.moveTo(h12._x, h12._y);
curve_mc.curveTo(ctl._x, ctl._y, this["h" add j]._x, this["h" add j]._y);
}
}
onMouseUp = draw;
//setInterval(draw, 25);
stop();

[F8] Adding Easing To Menu OnMouseUp
Hey guys,

I've got an interface that has horizontal line of thumbnails. When I click a left or right arrow the line of thumbnails moves either right or left respectively. This all works fine using the following code:


Code:
var mouseListener:Object = new Object();
Mouse.addListener(mouseListener);
var moving:Boolean = false;
mouseListener.onMouseDown = function()
{
moving = true;
panelOver();
}
mouseListener.onMouseUp = function()
{
moving = false;
panelUp();
}

function panelOver()
{
this.onEnterFrame = scrollPanel;
}
function panelUp()
{
delete this.onEnterFrame;
}


function scrollPanel()
{
if ((left.hitTest(_root._xmouse, _root._ymouse, true)) || (right.hitTest(_root._xmouse, _root._ymouse, true)))
{
for (var i=0; i<numOfItems; i++)
{
var t:MovieClip = home["item"+i];
var xdist = _xmouse - Stage.width/2;
t._x += -xdist / 2;
}
}
}


What I want though is on the MouseUp event for the menu to gradually slow rather than stop dead. So I want to apply easing to it. I've tried implementing some easing equations to no avail.
Can anyone point me in the right direction?

Many thanks
Matt

AttacheMovie OnMouseUp Depth Problem
Hey all,

I'm using an Actionscript class to attach movieclips to the stage. Five of the movieClips I attach are buttons that each have different behaviours when they are clicked. The problem is that only the onMouseUp function that is run is always the one the highest depth. Anyone know how to work around this?

Thanks in advance

Adding Sound To MovieClip OnMouseUp?
Adding Sound to a Movie Clip onMouseUp ????  Also how do I get a movie clip to play only certain frames (1 - 60) during RollOver and then the rest (61-80) onMouseUp??

Controlling Falling Particles With OnMouseDown & OnMouseUp
I was playing around with a falling particles tutorial I found online where the particles seem to drip off the mouse position. I wanted to modify the code so that the particles only appear when the mouse is pressed down and stop when the mouse is released.

The onMouseDown event works just fine but I can't seem to turn off the flow wnen the onMouseUp event is called. The particles and the glow behind them are placed on the stage via attachMovie() and the instance names are incremented dynamically. I suspect that this is where my problem is since I can't figure out how to disable the attachMovie() when my mouse is up.

Anyway, here is my code:
PHP Code:



var i:Number = 0;
var glowBall:MovieClip;
var star:MovieClip;
_root.onMouseDown = function() {
    this.onMouseMove = function() {
        glowBall = this.attachMovie("animatedGlow", "glowBall", 1);
        star = this.attachMovie("fallingStar", "fallingStar+1++", _root.getNextHighestDepth());
        glowBall._x = _root._xmouse;
        glowBall._y = _root._ymouse;
        star._x = _root._xmouse;
        star._y = _root._ymouse;
        star._xscale = star._yscale=Math.random()*30+3;
    };
};
_root.onMouseUp = function(){
    glowBall.removeMovieClip();
    star.removeMovieClip();
}; 




And here is my .fla file

Appreciate any help.

[flash8] Is This An Issue With Scope? No, Not Bad Breath, The Other Kind Of Scope
I feel like such an idiot. This *should* have been a really simple operation and it's turned into an hour-long issue. I've been trying to migrate from putting my button code on buttons and move the code onto the timeline instead. However in this instance it no workie . The following code, specified for cancelMC affects every other button in this scene as if I'd written the code with(this){.

If someone would please just scan this code, and/or look at the picture and tell me what key ingredient I am missing I would really appreciate it:

ActionScript Code:
with(this.cancelMC){        onRollOver = function(){            this.ExplainMC.gotoAndStop("cancel");        }        onRollOut = function(){            this.ExplainMC.gotoAndStop("void");        }        onRelease = onReleaseOutside = function(){            _root.searchPanelMC.gotoAndStop(15);            gotoAndStop("user");        }    }

the code is on the timeline and so is the button (cancelMC). However, the code is on the first frame and the button exists on multiple frames thereafter. Does this matter? Does that put the button outside the scope of the code? I tried an onEnterFrame to no effect.

How To Make OnMouseUp Event Affect Only One Movie Clip ?
Hello,

I have three movie clips that act like buttons. All three are inside another movie clip which is loaded using attachMovie. I want each movie clip when clicked link to a different page. The problem is when I click on one button all buttons respond and execute the code in their listener function. I tried two different ways of defining the listener functions but the results were the same. In both cases all movie clips responded to a single click on only one of them.

Could anyone please suggest what may be the problem and how to fix it? I searched different message boards for this problem, seems no one else has this problem. The following is my code for defining the listener functions which is pretty standard.


Code:
(Method 1 tried)

onClipEvent(mouseUp){
getURL("flash.html", "_self");
}


Code:
(Method 2 tried)

button_instance.onMouseUp = function()
{
getURL("flash.html", "_self");
}

Huh?: MyFunc = {func:func, Scope:scope, Args:args }
Hi,
I've seen this strang syntax used for functions (I think that's what I've seen anyway). Things like:

Code:
myFunc = {func:func, scope:scope, args:args };
in the above I think func is a function and scope is the critter that is supposed to call the function and args are the arguments? But I dont really understand how it works. How do you call myFunc in the above? How do you write a function using this syntax?

Or am I totally off here?

Can anyone help?

I Need Some Scope (pu)
Howdy
I'm doing a dyn. .txt based "news-reader"...
5 dyn txt files, 5 buttons, one dyn text field (box)
with variable name of "display".

My site is based on a main page at level_0, and I load swf's throughout to
various levels. My news reader works great in a stand alone config (when
testing in ie or flash player). When in the main movie, it fails to load txt files when i call it up to
a level, although it does load the buttons and it's
graphical elements. Code is as written

Heres the code on the _root of the news reader:

frame 1 of root,

loadVariablesNum ("content.txt", 0);
loadVariablesNum ("content2.txt", 0);
loadVariablesNum ("content3.txt", 0);
loadVariablesNum ("content4.txt", 0);
loadVariablesNum ("content5.txt", 0);
this._x=170
this._y=20

txt's are named as above...content.txt, etc.

first line inside the text files read:

dynamicText=<HTML><BODY>This is where we go to drink ale...(snip)
dynamicText2=<HTML><BODY>That is where we go to sober up...(snip)

etc.

button code goes:

on (release) {
display = dynamicText5, 5;
}

etc.

Again, this thang works great as long as I fire it up by itself. Inside my
main movie, it loads to the level to which I call it, including all graphic
elements, but onRelease, nothing happens with the txt's which should rear
their beautious heads.

Ideally, I would have my main page at level_0,
a nav swf at level_1 that has a button that calls the reader into level_3.

I've got the feeling this is a variable scope issue, but alas, rank amature
here...

Thanks in advance for any comments, codes or critiques.
Willy B.
(ps, this "txt.reader" is closely based on the "Regenerate" tutorial
in foe nmf 2002 annual).

Scope
Ok, maybe I am having a scope problem here?

can't get...


_level20.button1_mc.onRelease = function() {
play();
};


to give me the hand cursor. This code is on level 1. "interface.swf" is in level 20 and loads (I see the graphics). MC, instance name, "button1_mc" is on level 20's root. Yet, I rollover it...nothin'. But this works in a swf without using levels. (minus the_level20. code)

Can you have that code on level one, defining an event for a button on level 20? What's wrong?
??

Thanks,
rez

Scope
i'm makin a fps shooter where u use a sniper in 1 level and iono how 2 make one. i figure u have 2 say sumthin in the actionscript to tell it to go to a certain magnifacation if its in a certain area (where the scope is) but iono how 2 do this. can anyone help me. P.S. i was gonna put this question on games but it seemed 2 be a newbie kind of qwestion. iono. mayB i shuldnt have. srry

A Little Scope Help?
Hi all,
Think I could use a little scope help here. My function below splits a string, then attaches an mc for each item in the resulting array. A trace of the array contents returns correctly in the loadNavItems function. Within this function I have an onRelease function, but cannot seem to target the array the same way - trace returns undefined. What am I missing?


ActionScript Code:
function loadNavItems(navItems:String) {
    var navItems_array:Array = navItems.split(",");
    for (var i = 0; i<navItems_array.length; i++) {
        trace(navItems_array[i]); // traces correctly
        var navTxt:Object = dfSite.navHolder_mc.nav_mc.attachMovie("navTxt_mc", "navTxt"+i, i);
        navTxt.navBtn_mc.onRelease = function(){
            trace("linkTo "+navItems_array[i]); // undefined
        }
    }
}

Thanks for any help.

Scope
I am trying to understand the scope of different things and have written a simple class and fla to use it.


Code:
class instance {
public function getScope(){
trace("from class: " + _root);
trace("from class: this._parent);
trace("from class: " + this);
}
}

Code:
trace(_root);
trace(this);

var scope:instance = new instance();
scope.getScope();
The output I get it:


Code:
_level0
_level0
from class: _level0
undefined
from class: [object Object]
It all makes sense except for the last line, why does it say that? Everything is a subclass of object right? So I guess it makes sense for this intstance, but say I change me class to extend MovieClip, then it would seem that the last line in the out put should say object MovieClip or something like that.

And then why does this._parent return undefined? Isn't that the same as _root in this case?

Scope In As2
Im running into a scope issue with the below (only constructor shown)

Code:
function Excel() {
//constructor
trace("Excel Importer built");
this.swapDepths(5);
this.state = "in";
this.bttnClose.onPress = function() {
if (_parent.state == "in") {
var myTween = new Tween(_parent, "_x", mx.transitions.easing.Regular.easeOut, -626.5, 0, 1, true);
} else {
var myTween = new Tween(_parent, "_x", mx.transitions.easing.Regular.easeOut, 0, -626.5, 1, true);
}
this.enabled = false;
//trace("myTween "+myTween);
myTween.onMotionFinished = function() {
trace("state "+state);

if (_parent.state == "out") {
_parent.state = "in";
_parent.bttnClose.enabled = true;
} else {
_parent.state = "out";
_parent.bttnClose.enabled = true;
}
};
};
}
the tween onMotionFinished seems to have its own scope and i cant refer to find out what "state" is
is this a delegate.create thing ?

thanks

Scope:help
Hi everyone,
I'm a bit of a newbie to flash, and i'm not sure-how do u ensure that your variables are scoped locally to a scene only, and does not exist for all scenes?
-Nsmarina

The Scope Of This In AS3
Hi
I am just trying to understand the scope of this in AS3 for example in AS2

basicM_btn.onRelease = function() {
this._visible = false;
}

Would have made the button invisible
In AS3 I was expecting to write the same thing as this

function clickHandler(event:MouseEvent):void {

this.visible = false;

}

menuA_btn.addEventListener(MouseEvent.CLICK, clickHandler);


However this sets all of the content on the stage to visible = false
Is there a difference in the way that this works in AS3

Thanks for your help

Scope
Hi guys

I am developing a mobile application for the new Nokia N95 but i am having some problems. This is Flash Lite 2.0 by the way.

I want to use the softkeys to unload movieclips so that i can go back.

I have for instance, 2 classes

This is my infoClass. As you can see i am sending a _root.container_mc to my softKeyClass's constructor. This is all good and works fine.


PHP Code:



class infoClass extends MovieClip {        private var container_mc:MovieClip;    public function infoClass() {                softKeys();                trace("constructor is running");            }            public function softKeys() {                var mySoftKey:softKeyClass = new softKeyClass(_root.container_mc);    }            } 




But, then i wants put that into my softkeys and this is where it goes bad. I know that i am out of my scope becuase i am in the object.


PHP Code:



class softKeyClass extends MovieClip {        private var _target_mc:MovieClip;    private var test_btn:Button;    private var info_mc:MovieClip;        public function softKeyClass(target_mc:MovieClip) {                _target_mc = target_mc;                trace(target_mc +" target_mc");                trace(_target_mc + " _target_mc");                fscommand2 ("SetSoftKeys", "quit", "send");        fscommand2 ("FullScreen", true);        var myListener:Object = new Object ();                myListener.onKeyDown = function () {                        if (Key.getCode () == ExtendedKey.SOFT1) {        // Handle left soft keypress event.                //_root.target_mc.unloadMovie();                trace("left soft key");            }            else if (Key.getCode () == ExtendedKey.SOFT2) {        // Handle right soft keypress event.                _target_mc.unloadMovie();                trace("right soft key");            }        }            Key.addListener (myListener);    }} 




I thought to my self, why not use the delegate class, but i cant get it to work. Is there anyone who can help me out?

This is what i tried with the delegate class.


PHP Code:



import mx.utils.Delegate;class softKeyClass extends MovieClip {        private var _target_mc:MovieClip;    private var test_btn:Button;    private var info_mc:MovieClip;    public function softKeyClass(target_mc:MovieClip) {                        _target_mc = target_mc;                trace(target_mc +" target_mc");                trace(_target_mc + " _target_mc");        fscommand2 ("SetSoftKeys", "quit", "send");        fscommand2 ("FullScreen", true);                //Key.addListener(Delegate.create("onKeydown", this, getKey));                var myListener:Object = new Object ();                myListener.onKeyDown = Delegate.create(this, getKey);     }            private function getKey() {                    if (Key.getCode () == ExtendedKey.SOFT1) {        // Handle left soft keypress event.                //_root.target_mc.unloadMovie();                trace("left soft key");            }            else if (Key.getCode () == ExtendedKey.SOFT2) {        // Handle right soft keypress event.                _target_mc.unloadMovie();                                trace(_class._target_mc + " med parent");                        trace("right soft key");            }                        Key.addListener (myListener);    }} 




I am sorry for my bad English, i hope you guys understand what i am trying to do.

/Morten

Scope When Using New
i'm not sure how scope works in actionscript - am i doing something wrong in the code below?

the loop runs 3 times, so there should be 3 movieclip loader objects and 3 listeners. but in the output, there is only 1 "loaded" trace. i.e. only one of the listener objects has called the onLoadInit function.

any advice appreciated!

CODEtrace("length "+content_xml.firstChild.childNodes.length);
        for (var i = 0; i < content_xml.firstChild.childNodes.length; i++) {
            var lo = new Object();
            var mcl = new MovieClipLoader();
            createEmptyMovieClip("floorplan"+i, this.getNextHighestDepth());
            mcl.addListener(new Object());
            lo.onLoadInit = function() {
                trace("loaded");
                floorplans[i]._width = floorplanWidth;
                floorplans[i]._height = floorplanHeight;
                floorplans[i]._x = offStageRight;
                floorplans[i]._y = floorplanY;
            };
            trace("loading "+content_xml.firstChild.childNodes[i].attributes.image);
            mcl.loadClip(content_xml.firstChild.childNodes[i].attributes.image, eval("floorplan"+i));
        }

Scope Of Variables
Hey, Flash maniacs!
In all the books that I'm reading it says that a variable is scoped to its timeline, but they all talk about the root timeline as one timeline. What if there are 2 or more scenes in my movie? If I initialize the variables in scene one, can I still use their values in the other scenes or since these are different timelines I have to reassign values to them?
Thanks for enlightening me whenever I need it! This is a great forum!
Have fun!

Functions: What Is Their Scope?
If I write my own function, what is it's scope?

Say if it's in the main timeline...
Or if it's in a movie in a movie that is onw the main time line...?
What is it's scope?

Any help would be appreciated.

Thanks.


Nav

Scope Issues - Please Help
I am following along with O'reilly's Actionscript, the definitive guide, and having trouble with very basic scope problems I'm sure someone can help me with. On frame 1 of my main timeline I have the code :

trace (square.x);
trace (circle.y);

and I also have instances [named square and circle] of 2 symbols on this frame. On each symbols main timeline [frame 1] I have this code:

var y;
y = 4;

and

var x;
x = 3;

And for some reason that the book doesn't explain this wont work. It prints out blank, like my dot syntax is wrong or something. However when I move the code on frame one of the main timeline to frame 2 it works. Why is this and how can I fix it?

Thanks a lot!
Jeremy
Programming Art

http://www.programmingart.com

Scope And Rotation
Ok I have tried two other threads and no one can answer this for me maybe it is so hard I don't know but its bugging me out I can do it in flash 5 code but I wanted to get used to flashMX code so I tried this but it just isn't working. I have got the dots to attach and space out right but I wanted each of them to have a rotational value according to the mouse. But I think I have the scope all wrong can anyone please help

Code:
clipDistance = 40;
xRow = 6;
yRow = 3;
total = xRow*yRow;
for (i=0; i<xRow; i++) {
for (j=0; j<yRow; j++) {
movieNum++;
tempClip = _root.attachMovie("dot", "dot"+i+j, movieNum);
tempClip._x = 200+(clipDistance*j);
tempClip._y = 100+(clipDistance*i);
}
}
with (tempclip) {
tempclip.onEnterFrame = function() {
this.rot = (Math.atan2(_root._ymouse-tempclip._y, _root._xmouse-tempclip._x)/Math.PI)*180;
_root.dot._rotation = this.rot;
};
}

Function Scope
I have defined a function the first frame of my timeline but components inside MC's are not picking it up. Any idea's? Do I have to have my function in the first scene?

Variable Scope
If I declare a variable in a movie clip, can I access it in another movie clip? If so, how?

Ya-Tin

Variable Scope
Hello --
I hope someone can help me -- I seem to be losing the value in an some variables I have:
I am new to Flash and am trying to make a simple (or so I thought!) movie with a text box displaying a list of current events, one by one. I want to store the events in an array, and have the first one display in a dynamic text box for a few seconds (maybe scroll across the screen), then display the next array item (next current event), then the next, and so on.
I have a movie with 2 layers: Actions and Display. My code so far is in the first frame of the actions layer.
The Display layer contains a dynamic text box set to the variable "newsitem" - this is where I want to display my events.
I have a text file (news.txt) containing the events, each event separated by a carat ("^").
Contents of text file:
txtmsg=October 20-21, 2002 FIN User Conference, Van Nuys, CA^November 2-3, 2002 Vancouver Tech Conference, Vancouver, BC

I load the text file into a Flash variable (txtmsg) (this part works fine). I then use the split function to separate out each event into its own array item. Here's my code from frame 1 of the actions layer:
loadVariablesNum ("news.txt", 0, "POST");
mycounter = 0;
newsarray = txtmsg.split('^');
newsitem=newsarray[mycounter];

This works fine (meaning when I test the movie, and choose Debug - List Variables, each event is listed as an array item.)

BUT when I go on to the next step, and add 20 frames to each layer(where the first newsarray item would display in the text box newsitem), and add this piece of code in frame 20 of the actions layer to bring in the next array item and display it in the text box newsitem:
mycounter++;
newsitem=newsarray[mycounter];
gotoAndPlay (2);

When I add this code, and test the movie, the variable newsarray is "undefined", as is newsitem. The variable "txtmsg" which contains the unsplit text straight from the text file, still contains its original value.


I don't know if somehow the variable containing the array is going out of scope, or what!
Can someone please tell me what I'm doing wrong?

Thanks!
Kathy

Scope Issue
if i create an onLoad function for an MC in it's parent MC and call a function in the onLoad that exists in the child, how do I reference that funciton...here's the set up

two MC's: A, B

in A I write:

//
function init() {
foo()
}

B.onLoad = init;

in B I write:

//
function foo() {
trace("init");
}

since foos is defined in B, should I call it like so B.foo or as is?

tx

Embedded MC Scope
How can you call an Object method from an embedded MC onEnterFrame Event. Its another problem with scope that i cant figure out

Code:

function newTarget()
{
this.MyClip=attachMovie( "fly", "fly1",100);
this.MyClip.onEnterFrame=function()
{
//'this' here refers to the MyClip Instance, i need to target its object parent
this.Update()
}
}

newTarget.prototype.Update=function()
{
trace("called")
}

newClip=new newTarget()

I've tried various different solutions and cant get it to work. Any help or pointers appreciated.

Cheers

Object Scope From MC
How can you call an Object method from an embedded MC onEnterFrame Event. Its another problem with scope that i cant figure out

Code:

function newTarget()
{
this.MyClip=attachMovie( "fly", "fly1",100);
this.MyClip.onEnterFrame=function()
{
//'this' here refers to the MyClip Instance, i need to target its object parent
this.Update()
}
}

newTarget.prototype.Update=function()
{
trace("called")
}

newClip=new newTarget()

I've tried various different solutions and cant get it to work. Any help or pointers appreciated.

Cheers

Variable Scope
Hello,
nice easy one for ya
I have a function on the main time line that basicly creates and array
All I wan't do is access that array from within another function - should be easy but cant remember for the life of me how to do it????

I'll include a bit of an example for clarity -

//function 1

function makeArray(){
dest = -10 + random(780);
speed = 10+ random(5);
direc = random(2)
return man = [dest, speed, direc];
}

//function 2
function move{
man[1] yada yada yada
}
You get the point
any help happly recieved

(sorry about spelling was in bit of a rush)

GetTimer - > Scope
I am building a little pre-loader and I wish to use the getTimer() function. However, the file I am loading is loaded into a movie clip ("movieHolder") in my main movie which is the _root timeline. Please see the following code.


// Code in externally loaded movie
this.stop();
// preloading routine
this.onEnterFrame = function() {
fractionLoaded = this.getBytesLoaded()/this.getBytesTotal();
elapsedTime = (getTimer()-_root.movieHolder.startTimeDemo)/1000;
timeToLoad = elapsedTime/fractionLoaded;
timetoFinish = Math.ceil(timeToLoad-elapsedTime);
if(timetoFinish == "0") {
// move playhead to correct position
this.gotoAndPlay("demo");
}
};

_root.movieHolder.startTimeDemo = getTimer();

When I run the main movie, it picks up the "bytesLoaded" but does not trigger the timing function.

I have found that when I use the setInterval function, I can only get code to work if everything is referenced around the _root timeline. Is this a similar case / problem with getTimer() ?

I have tried some other referencing, but I am shooting in teh dark. Is there a definitive answer ?

Regards,

motorpilot

When Does TextHeight Come Into Scope?
I have code in a prototype defining a text field as so:


Code:
DraggerClip.createTextField("tf_draggerText", ++this.depthCounter, 0, 0, 0, 0);
DraggerClip.tf_draggerText._width = 160;
DraggerClip.tf_draggerText.multiline = true;
DraggerClip.tf_draggerText.wordWrap = true;
DraggerClip.tf_draggerText.autoSize = "left";
DraggerClip.tf_draggerText.html = true;
DraggerClip.tf_draggerText.leading = 0;
DraggerClip.tf_draggerText.htmlText = "<p align='center'>" + getDrag2Text()+ "</p>";
DraggerClip.tf_draggerText.embedFonts = true;
DraggerClip.tf_draggerText.setTextFormat(new TextFormat("Futura Md BT", 15));
DraggerClip.tf_draggerText._x = Drag2LeftMargin;
DraggerClip.tf_draggerText._y = DraggerClip.title_txt._y+DraggerClip.title_txt._height+50;

trace(DraggerClip.tf_draggerText.textHeight);


A couple problems...
It displays ok unless i comment out the autoSize. Then no text is rendered on the stage. I don't understand that behavior...i've tried with several different width values without any change.

But my main problem is returning the height of the text. I need to pull this value so I can play a clip that adjusts the background depending on how many lines the field wraps to.

I was under the impression that this value was immediately available...no need to let a frame or 2 elapse as we did in the days of Flash 5.

Object Scope Help
postObj = {};
postObj.me=this.postObj
postObj.page = 10;
postObj.lastPage=this.page/2
trace(postObj.lastpage)

how come it doesnt trace out the correct number. Is it got to do with scope? how do i solve this prob?

Rifle Scope Help
I am working on a site that uses the magnifying lense from this tutorial Real Time Magnifying Glass but I have altered it so that I have some t-shirts in the middle of a scope rather than the newspaper from the example tutorial. What I want to do is to make it so that once you aim the rifle over the shirt you want, and click the mouse, a larger example of the shirt shows up in the top right part of my flash window. Any help here would be appreciated. rifle.swf example<--copy link to clipboard, then paste in a new window for the link to work properly.

Path Or Scope?
Hi,

I have a very simple case to solve, but I can't figure out what's wrong. I guess that it has something to do with path or scope syntax.

Here's the scenario: I have 3 scenes (Scene 1, Scene 2 and Scene 3). Every scene has only 1 frame and a stop() instruction in frame 1.

My first example has a button in Scene 1 with the following script attached:

Quote:




on (release) { gotoAndPlay ("Scene 3",1); }




Things are working well, and as expected, when clicking it, the playhead jumps to first frame of Scene 3 and plays (in fact stops because I have a stop() there).

My second example, the one I can't solve, is slightly different. This time, in Scene 1, I have a movie clip and inside it there is my button with the same script attached. But this time the playhead doesn't jump where it was supposed to. Nothing happens.

So my questions are:

1. Why is that?
2. What is the correct syntax for the second case?

Thank you.

P.S. You can download these 2 examples from here:
working.fla and not_working.fla

Note: Macromedia Flash MX Professional 2004 needed.

Tracing Scope
hi.

i'm having some serious scope issues and want to know what the best way to troubleshoot this is.

i've traced as much as i can and couldn't figure it out, then i tried using targetPath() but that only works for finding movie clips and i'm looking for an array. any ideas?

thanks. fumeng.

Scope Within AS2 Classes
Hi,

See comment in class



Code:

class InstructionItem {

var mc:MovieClip;
var sndSound:Sound;


// CONSTRUCTOR
public function InstructionItem(clip,soundLinkageID):Void{
this.mc = clip;
this.mc.InstructionItem = this; // This is to be able to call the class methods from within this.mc.onEnterFrame haldlers for an example
this.sndSound = new Sound(this.mc._parent);
this.sndSound.attachSound(soundLinkageID);
}

// PUBLIC METHODS
public function playInstructions():Void{
this.sndSound.start();
this.sndSound.onSoundComplete = function(){

/*
I want to reach the class's methods & properties from here
like if I want the mc MovieCLip to play I would do maybe:
this.mc.play();

I know "this" refers to the Sound object so I can't do that. This
is a scope matter. But how to I do it then?

I suppose I could do the same as with mc - add a property to it
that I can then use within onEnterFrame and such to call the methods
but I have not been able to do it for the Sound object.
I always thought it was "a wrong way" anyway.

Please help me :)

*/
};

}


}

Copyright © 2005-08 www.BigResource.com, All rights reserved