A Flash Developer Resource Site

Results 1 to 11 of 11

Thread: [F8] Don't understand???

  1. #1
    flash animator guy
    Join Date
    Oct 2006
    Location
    Daly City
    Posts
    219

    [F8] Don't understand???

    ca any one tell me why these don't work (in one case, one of the worked once and then not any more, the first one) In the later 2 scripts I am referencing a button instance. On the last script, the trace works but the start drag dose not:

    _root.headder.name_email.onRelease=function() {
    getURL ("mailto:rsbelotte@yahoo.com?subject=I have a job for you");
    }


    this.headder.name_email.onRelease = function() {
    trace ("good");
    }


    this.sound.drag_but.onPress=function() {
    this.sound.startDrag;
    trace("test");
    }

  2. #2
    flash animator guy
    Join Date
    Oct 2006
    Location
    Daly City
    Posts
    219
    I looked up the reference and it looked like I was using start Drag wrong so I re wrote it like this (according to adobe flash reference library):

    this.sound.muse_drag.drag_buttn.onPress=function() {
    startDrag(this.sound);
    };

    Unfortunately It still doesn't work.

    Any ideas?

    Also this isn't working and it's about as simple as it could be, so I don't know what the problem is.

    this.headder.name_email.onRelease=function() {
    getURL("http://rbelotte.net");
    trace("bad times");
    };

    The trace doesn't even work.

  3. #3
    Senior Member
    Join Date
    Aug 2002
    Location
    Dublin, Ireland
    Posts
    1,749
    Your problem is that you need to learn a bit more about variable scope. Moock (Essential ActionScript 2.0 is a good reference).

    If you do a trace(this); inside the onPress function, you will see that it refers to this.sound.muse_drag.drag_buttn. Therefore, this.sound refers to this.sound.muse_drag.drag_buttn.sound ... which doesn't exist. Try altering the startDrag to something like:

    startDrag(this._parent._parent);

    For the other thing, did you see that headder has two d's? Check your typing.

  4. #4
    flash animator guy
    Join Date
    Oct 2006
    Location
    Daly City
    Posts
    219
    Hey there AlsoGaiusCoffey

    Thanks for the input.

    I corrected the typo and just modified it to something simpe to test:

    this.header.button1.onRollOver=function() {
    //getURL("http://rbelotte.net");
    trace("bad times");
    };

    And it still doesn't work. Any other ideas?

    In regards to the scope, you are right thank you. Instead of _parent though I used _root.

  5. #5
    flash animator guy
    Join Date
    Oct 2006
    Location
    Daly City
    Posts
    219
    OK can you tell me why this doesn't work? It maybe the scope but I'm using flashes vary own "target path" tool, so if it's scope, flash doesn't know how to do it either.

    stop();

    nav.navText._visible = false;

    _root.nav.navBut.neuroM.onRollOver=function() {
    _root.nav.navText.gotoAndStop("neuro");
    _root.nav.navText._visible=true;
    };

    _root.nav.navBut.neuroM.onRollOut=function() {
    _root.nav.navText._visible = false;
    };
    Last edited by belotte; 07-11-2008 at 02:28 AM.

  6. #6
    Senior Member
    Join Date
    Aug 2002
    Location
    Dublin, Ireland
    Posts
    1,749
    Scope is not just about getting the path right, but also about where you are when the function is called. Flash's targetPath tool will only tell you the path to the object from the timeline, but scripts will often execute somewhere very different.

    I recommend playing around with variations on the following until you get the idea:
    Code:
    var a = 1;
    var b = 2;
    function myFunction() {
    	var c = a+b;
    	var d = this.a+this.b;
    	var me = this;
    	trace("@@@@@@");
    	trace("myFunction called by: "+this);
    	trace("\tValue a is: "+a);
    	trace("\tValue b is: "+b);
    	trace("\tValue c = a+b is: "+c);
    	trace("\tValue d = this.a+this.b is: "+d);
    	trace("\tValue this.a is: "+this.a);
    	trace("\tValue this.b is: "+this.b);
    	doSubfunction();
    	trace("\tAPPLYING FUNCTION AS "+me);
    	doSubfunction.apply(me);
    	trace("######");
    	function doSubfunction() {
    		var c = a+b;
    		var d = this.a+this.b;
    		var e = me.a+me.b;
    		trace("\t\tWithin subfunction: "+this);
    		trace("\t\tValue a is: "+a);
    		trace("\t\tValue b is: "+b);
    		trace("\t\tValue c = a+b is: "+c);
    		trace("\t\tValue d = this.a+this.b is: "+d);
    		trace("\t\tValue e = me.a+me.b is: "+e);
    		trace("\t\tValue me is: "+me);
    		trace("\t\tValue me.a is: "+me.a);
    		trace("\t\tValue me.b is: "+me.b);
    	}
    }
    
    // Add the function as a property of the movieclip
    var my_mc:MovieClip = this.createEmptyMovieClip('my_mc', this.getNextHighestDepth());
    my_mc.a = 47;
    my_mc.b = 56;
    my_mc.callFunction = myFunction;
    
    // And to another movieclip
    var my_mc2:MovieClip = my_mc.createEmptyMovieClip('my_mc2', my_mc.getNextHighestDepth());
    my_mc2.a = "A string of text for value a";
    my_mc2.b = "A string of text for value b";
    my_mc2.callFunction = myFunction;
    
    // Now everything is set up, try calling the function in the different scopes
    myFunction();
    my_mc.callFunction();
    my_mc2.callFunction();
    This is a good reference to begin with:

    http://livedocs.adobe.com/flash/mx20...=00000785.html

    NB: Note the reference to "avoiding _root". Excessive _root use makes your work almost impossible (or at least, a pain in the arse) to integrate with anybody else's. There are only about two occasions where I use _root and I do my damnedest to avoid having to use them.

    Finally, as for your code not working... well, it does (see below). So if nothing is happening, check you have the paths correct. Oh, and BTW, you don't need to use _root to get that working. It works either way.
    Code:
    function box(tgt, col) {
    	var w2:Number = 100;
    	tgt.moveTo(0,0);
    	tgt.beginFill(col,100);
    	tgt.lineTo(-w2,-w2);
    	tgt.lineTo(w2,-w2);
    	tgt.lineTo(w2,w2);
    	tgt.lineTo(-w2,w2);
    	tgt.lineTo(-w2,-w2);
    	tgt.endFill();
    }
    
    var mc = this.createEmptyMovieClip('nav', this.getNextHighestDepth());
    box(mc,0xFF0000);
    mc._x += 50;
    mc = nav.createEmptyMovieClip('navText', nav.getNextHighestDepth());
    box(mc,0xFFFF00);
    mc._x += 50;
    mc = nav.createEmptyMovieClip('navBut', nav.getNextHighestDepth());
    box(mc,0xFF00FF);
    mc._x += 50;
    mc._y += 50;
    mc = nav.navBut.createEmptyMovieClip('neuroM', nav.navBut.getNextHighestDepth());
    box(mc,0x00FFFF);
    mc._x += 50;
    
    nav.navText._visible = false;
    
    nav.navBut.neuroM.onRollOver = function() {
    	nav.navText.gotoAndStop("neuro");
    	nav.navText._visible = true;
    };
    
    nav.navBut.neuroM.onRollOut = function() {
    	nav.navText._visible = false;
    };

  7. #7
    flash animator guy
    Join Date
    Oct 2006
    Location
    Daly City
    Posts
    219
    Hello AlsoGaiusCoffey.

    Thanks for the input.

    It doesn't really help though. It's a bit to complex for me to understand with the variables and functions, etc. I need the simplest explanation posible.

    As for my code working or not... I know the code is good. Therefore I know it's the path (scope) that I have wrong. But as previously stated, I don't know how to correct it as I don't seem to understand scope very well. I amused if you started with "_root" it was a simple path down to what you needed no mater where you were calling it from. Obviously that's not correct.

    As for excessive use of "_root", I know it's bad. But I figured it was the best way to proceed with what I am trying to do. Again I seem to be wrong.

    Thanks any way though

  8. #8
    flash animator guy
    Join Date
    Oct 2006
    Location
    Daly City
    Posts
    219

    Scope it or not?

    OK so to go further and ask more...I have the following on the root time line

    header.button1.onRollOver=function() {
    //getURL("http://rbelotte.net");
    trace("bad times");
    };



    I have a button with the instance name of button1, it's nested in side of a movie clip with the instance name of header, which also is on the stage in the main time line. This is very simple, but I cant get it to work. The isue of scope doesn't even really apply to this dose it? what's going wrong with this?

    PS I also tried it with button1 being a movie clip instead but that didn't work either.

    OK I've done some testing and I have 2 clips in the root time line, constructed exactly the same, and in the same place. I am also using the following AS

    this.testMC.testButton.onRollOver=function() {
    trace("good");
    };

    this.header.button1.onRollOver=function() {
    trace("stuff");

    };


    Both of which are in the same frames on the root time line. So one works (the first) and one dose not, the code is virtually the same with the exceptions of the instance names. How is this posible?
    Last edited by belotte; 07-15-2008 at 06:44 AM.

  9. #9
    flash animator guy
    Join Date
    Oct 2006
    Location
    Daly City
    Posts
    219
    OK so I've done some extensive testing and I know now for sure it's not an isue of scope (I was pretty sure I had done it right).

    But I don't know what the problem is now?

    Any ideas?
    Last edited by belotte; 07-15-2008 at 07:51 AM.

  10. #10
    Senior Member
    Join Date
    Aug 2002
    Location
    Dublin, Ireland
    Posts
    1,749
    Couldn't tell you without seeing your Flash file. But I still reiterate the recommendation that you get your head around scope.

  11. #11
    flash animator guy
    Join Date
    Oct 2006
    Location
    Daly City
    Posts
    219
    Yes I do agree.

    I've don a search on the web and found a bit of info.

    Can any one make some suggestions on articles either in magazines, books or the web?

    Thank you so very much

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center