-
Designer, Programmer, Musician
[RESOLVED] Nested functions function1.().function2();
Hello,
i'm making a class to navigate a timeline ( i hope publishing it soon)
It is working perfectly, just that i read something in another class or something i read on the internet, and I saw something like this:
function1().function2();
And i searched for it but i don't know how it's called. I tried "Nested functions" , mergin 2 functions, Multiple functions, function next to the other, and I didn't find anything.
It's something as when we replace a text in a String:
myString.split().join();
We use join next to split. I tried making 2 public classes in my main class, una called function1, the other function 2, each one has a trace and i create a instance of the class:
var mc:Main = new Main();
mc.function1().function2();
But only the function 1 was fired, and i got an error, so i guess the function 2 is not being called.
Thank you
Already mastering AS3. It was so fun. Now into Javascript and PHP and all its libraries
-
.
Hi,
Attach your file Angel and a bit more explanation, errors etc
-
Designer, Programmer, Musician
Basically in don't have anything in the .fla. I just have this class named Test.as and in the first frame i created an instance of the class, and tried to fire its two nested functins but no success.
Test.as class:
package
{
import flash.display.MovieClip;
public class Test extends MovieClip
{
public function Test()
{
}
public function Coffee()
{
trace("making coffee");
}
function Milk()
{
trace("heating milk up");
}
}
}
Frame 1, main timeline:
var c:Test = new Test();
c.Coffee().Milk();
The function Coffee(); is being fired and the Milk() function not. So i was wondering how to nest 2 function as when we do split().join(); together
Thanks
Already mastering AS3. It was so fun. Now into Javascript and PHP and all its libraries
-
.
Hi,
Why not just use
PHP Code:
var c:Test = new Test();
c.Coffee();
c.Milk();
and alter your as file slightly too
PHP Code:
package
{
import flash.display.MovieClip;
public class Test extends MovieClip
{
public function Test()
{
}
public function Coffee()
{
trace("making coffee");
}
public function Milk()
{
trace("heating milk up");
}
}
}
-
.
Hi,
Or you could do it like so with no code in the *.fla file at all, ensuring you add the class pat.
There are numerous ways you can do this simple task.
PHP Code:
package
{
import flash.display.MovieClip;
import flash.events.Event;
public class Test extends MovieClip
{
public function Test()
{
Coffee();
}
function Coffee()
{
trace("making coffee");
Milk();
}
function Milk()
{
trace("heating milk up");
Drink();
}
function Drink()
{
trace("Tastes good!!");
}
}
}
-
Designer, Programmer, Musician
Yeah i know, thank you. I already have few classes made, and i have fews of private and public functions, even static and override.
But I saw this script only scrip that called my attention. Then i thought about the split().join() combination and i wondered how to make 2 functions call with Dot Syntax like the mentioned. I will keep reading, thanks again. Have a nice day.
Already mastering AS3. It was so fun. Now into Javascript and PHP and all its libraries
-
.
Hi,
Static and override have nothing to do with this yet, if you can manage the other stuff then surely you must have an inkling on how to do this.
Going back to your original -
PHP Code:
c.Coffee(c.Milk());
example, Test.as
PHP Code:
package
{
public class Test
{
public function a(num1:Number):Number
{
return num1 * 10;
}
public function b(num2:Number)
{
trace(num2);
}
}
}
fla timeline code
PHP Code:
var c:Test = new Test();
c.b(c.a(10));
-
.
Hi,
Me again with more,
PHP Code:
package
{
import flash.display.MovieClip;
public class Test extends MovieClip
{
public function Test()
{
}
public function Coffee()
{
trace("making coffee");
}
public function Milk()
{
trace("heating milk up");
}
public function Drink()
{
trace("ahhh - tastes good");
}
}
}
PHP Code:
var c:Test = new Test();
c.Coffee(),c.Milk(),c.Drink();
-
Designer, Programmer, Musician
Thanks. I know override and static don't have anything to do with this, i was just pointing out that i already know many things about classes, because i already have other classes in other projects i've built. I just was wondering how to make a DOT NOTATION FUNCTIONS MERGE as i've seen in other scripts:
function1().function2(); or split().join();
Thanks for your time, i appreciate it.
P.S.
I will show you later my Navigate Class. You can navigate any object timelines normal, reversed, half the timeline, set the speed (frame rate),
true to show the frames, the triggered object and the direction and the speed, or false to hide it, and more. It's really good. It is called like this:
var nav:Navigate = new Navigate(this); //create an instance and pass the stage as argument
nav.Begin(Object:Object, Target Frame:String or int, Direction:String("normal", "reverse", "half"), Speed:Number, Show Info:Boolean);
Cheers
Already mastering AS3. It was so fun. Now into Javascript and PHP and all its libraries
-
Don't put functions inside of functions. There's no need for it (it's a rule too).
Putting functions inside of functions is like putting functions in frames inside of scenes. You can do it, but once you get skills or are taught, you know it doesn't make sense.
Use methods - functions "inside" of objects. That is what you've been using since day one in actionscript. myButton.onRollOver(). onRollOver is a method - a function inside of an object.
-
Designer, Programmer, Musician
Thanks for the feeback, but i didn't put a function inside other function. I just was asking how to "fire" or "execute" 2 nested functions, as when we do this: split().join(); << we are calling split first then join, at the same time. But join() function construction is not inside split function construction. I have never put a function inside another function, that's a bad practice, and i know it since as2. But i was just wondering how to "fire" "execute" 2 functions simultaniously, as when we want to replace a text form a string, that we use split().join(); ( i know as3 has the replace() method). Anyway, i give up with this, i will keep firing my functions separatendly. Thanks.
Already mastering AS3. It was so fun. Now into Javascript and PHP and all its libraries
-
.
Hi,
You could also call them both from a function like so,
PHP Code:
myButton.addEventListener(MouseEvent.CLICK, combiFunction);
function combiFunction(e:MouseEvent):void
{
part1();
part2();
}
// or if you need params with your function calls
myButton.addEventListener(MouseEvent.CLICK, combiFunction);
function combiFunction(e:MouseEvent):void
{
part1(e.currentTarget);
part2(e.currentTarget);
}
-
Designer, Programmer, Musician
True that, thanks fruitbeard!
Already mastering AS3. It was so fun. Now into Javascript and PHP and all its libraries
-
Originally Posted by angelhdz
Thanks for the feeback, but i didn't put a function inside other function. I just was asking how to "fire" or "execute" 2 nested functions, as when we do this: split().join(); << we are calling split first then join, at the same time. But join() function construction is not inside split function construction. I have never put a function inside another function, that's a bad practice, and i know it since as2. But i was just wondering how to "fire" "execute" 2 functions simultaniously, as when we want to replace a text form a string, that we use split().join(); ( i know as3 has the replace() method). Anyway, i give up with this, i will keep firing my functions separatendly. Thanks.
Still reading everything as a challenge?
"nested functions" are functions inside other functions. Do you mean something else?
You don't call functions simultaneously. If your myFunction().myNestedFunction() call worked, it would call myNestedFunction() first.
You can say things are "running simultaneously" but code does not and can not. Like math: (2 + 4) * 5 != 2 + (4 * 5)
Last edited by moot; 04-03-2014 at 12:49 PM.
-
Designer, Programmer, Musician
What's your problem dude? You can say whatever you want, whenever you want, and if I say whatever i want, you call it a challenge? o.O Please. I won't reply to this anymore.
Already mastering AS3. It was so fun. Now into Javascript and PHP and all its libraries
-
Trust me, I don't say whatever I want. I don't say anything of the things I want to say to you. I just deleted one now. I stick to the code. Any chance of you doing that anytime soon?
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|