as3 unload from child - actionscript-3

I'm trying to unload a ProLoader from the child.
Code in main.swf
import fl.display.ProLoader;
var myProLoader:ProLoader=new ProLoader();
page2_mc.addEventListener(MouseEvent.CLICK, page2content);
function page2content(e:MouseEvent):void {
var myURL:URLRequest=new URLRequest("page2.swf");
myProLoader.load(myURL);
addChild(myProLoader);
}
function unloadcontent(e:MouseEvent):void {
myProLoader.unload();
}
Code in page2.swf:
return_mc.addEventListener(MouseEvent.CLICK,back);
function back(e:MouseEvent):void{
parent.parent['unloadcontent']();
}
When I run these, I get the following error:
ArgumentError: Error #1063: Argument count mismatch on _09Start_working_fla::MainTimeline/unloadcontent(). Expected 1, got 0. at page2_fla::MainTimeline/back()
I just want the mc in child.swf to unload the content of the ProLoader(back to main).
Thanks for help.
Regards,
Reidar Nygård

Your unloadcontent function expects an argument of type MouseEvent. In order to call it without having to pass one in, change it to:
function unloadcontent(e:MouseEvent = null):void

Related

Calling a function in Actionscript 3

I am trying to call a function using the function name and (); That is how I have done it in the past and how it is shown in examples on different sites. I get an error saying it is expecting 1 argument. Does calling a function require an argument?
Hi i have gone through your question you have said about calling function needed any argument here no needed they error says expecting 1 argument means you want to pass the event name in the function here in this example i have shown..
//creating event listener for card movieclip
card_mc.addEventListener(MouseEvent.MOUSE_DOWN, drag);
//In this function im passing the event name done (e:MouseEvent) likewise you want to do in the function then error will clear..
function drag(e:MouseEvent):void
{
var mc:MovieClip = MovieClip(e.currentTarget);
trace(mc.name);
mc.startDrag();
}
Thank You ...

typeError: Error #1006: setChildIndex is not a function

Do you know what causes this error?
TypeError: Error #1006: setChildIndex is not a function.
at Function/()[iVision_Game_fla.MainTimeline::frame83:151]
Here's where I think the error occurs...
function dragObject(indx1:int,indx2:int):Function {
return function(event:MouseEvent){
var item:MovieClip=MovieClip(event.currentTarget);
item.startDrag();
var topPos:uint=this.numChildren-1;
var itemSound:Sound = new Sound();
itemSound.load(new URLRequest("sounds/"+dirArray[indx1])+indx2+".mp3"));
if(!activeSound)
{
itemSound.play();
activeSound=true;
}
this.setChildIndex(item, topPos);
}
}
//calling it on another function
var functionOnDrag:Function = dragObject(indexc[count-1],index[count2]);
pb[i].addEventListener(MouseEvent.MOUSE_DOWN,functionOnDrag);
I think scope is the problem here. If the item's parent isn't changing, you can use item.parent.setChildIndex(item, topPos)
Also, before that, topPos:uint = item.parent.numChildren -1;
Update:
To debug further, put a breakpoint on the line of setChildIndex (151). (adding a breakpoint: click to the left of the line number. it will add a little red circle. When code hits this in debug mode it will stop.)
Then go to Debug -> Debug Movie -> Debug
When it stops, open the Debug Panels: Window->Debug Panels->Variables, Window->Debug Panels->Callstack
In the variable panel, you should see all the current variables in the scope. What you are looking for is an issue with the object that setChildIndex is being called on. In this case, the parent of item. You can drill down to see what that is. It should be a DisplayObjectContainer (MovieClip, Sprite, etc...). Item came from event, so i would check event.currentTarget as well. You are basically trying to confirm that at that breakpoint, item exists, it has a parent, and it's parent is a DisplayObjectController. If one of these isn't true, you can track backwards from here why this isn't the case.
TypeError: Error #1006: setChildIndex is not a function
You have created anonymous function, if you want capture this, you could do such construction:
var selfRef:MyClass = this;
Now your handler for the MouseEvent will look:
function dragObject(indx1:int, indx2:int):Function {
return function (event:MouseEvent) {
//Your code
selfRef.setChildIndex(item, topPos);
}
}

AS3 tweenlight loop stops

I have a loop animation that stops and gives me an argument error. I've redone the coding a couple of different ways but to no avail. Here is my code:
contactbox.addEventListener(MouseEvent.MOUSE_OVER, Scroll);
function Scroll(evt:MouseEvent){
TweenLite.to(
btnwave, 2, {
x:-115.5, ease:Linear.easeNone, overwrite:true, onComplete:Switch});
}
function Switch(){
TweenLite.to(
btnwave, 0, {
x:184.6, ease:Linear.easeNone, overwrite:true, onComplete:Scroll});
}
And here is the error it gives me:
ArgumentError: Error #1063: Argument count mismatch on Main/Scroll(). Expected 1, got 0.
at Function/http://adobe.com/AS3/2006/builtin::apply()
at com.greensock.core::TweenCore/complete()
at com.greensock::TweenLite/renderTime()
at com.greensock::TweenLite()
at com.greensock::TweenLite$/to()
at Main/Switch()
at Function/http://adobe.com/AS3/2006/builtin::apply()
at com.greensock.core::TweenCore/complete()
at com.greensock::TweenLite/renderTime()
at com.greensock.core::SimpleTimeline/renderTime()
at com.greensock::TweenLite$/updateAll()
I'm trying to brush up on my tweenlite skills for some upcoming work. Any help would be appreciated.
You're getting an error because TweenLite isn't passing a MouseEvent instance to Scroll(). Scroll() currently requires that a MouseEvent Object be passed to it since it's an event handler. You can fix this by making Scrolls first argument optional like this:
function Scroll(evt:MouseEvent=null){
This way, when TweenLite calls Scroll() the MouseEvent will just default to null.

AS3 Argument Error #1063 ... expected 1 got 0

So I got a very basic class
package {
import flash.display.MovieClip;
public class XmlLang extends MovieClip {
public function XmlLang(num:int) {
trace(num);
}
}
}
and an object at frame one:
var teste:XmlLang = new XmlLang(1);
I'm getting this error:
ArgumentError: Error #1063: Argument count mismatch on XmlLang(). Expected 1, got 0
What am I doing wrong?
Thank you very much for you help.
Something is up with your setup. I took your code and implemented it and it worked.
Here's what I did. I created a new test.fla file in AS3 and put the following code on frame 1 - no object on the stage, just code in frame 1.
import XmlLang;
var teste:XmlLang = new XmlLang(1);
stop();
Created a XmlLang.as file, copying your code exactly and saved it in the same folder as the test.fla. Compiled and got a trace of 1
So I'm not exactly sure what's going on. What version of Flash are you running?
Not sure if this was your case, but for future googlers: you get this error message when you're trying to initialize a vector but then forget the new keyword.
So this:
var something:Vector.<Something> = Vector.<Something>();
Will give you an error saying that Something had an argument count mismatch. The correct line is:
var something:Vector.<Something> = new Vector.<Something>();
Difficult error to get at a glance. Took me a few minutes to find it in my code, especially because it doesn't really give you the error line.
I expect you have an instance of XmlLang located on stage, that will be constructed using a constructor with 0 parameters, like an ordinary MovieClip. To check for this, change the constructor header to this:
public function XmlLang(num:int = 0) {
This way, if something will instantiate an XmlLang without a parameter supplied, the new instance will receive a 0 (the default value) as parameter. And then you check your trace output, I am expecting one or more zeroes appear, followed by an 1.

Error #1034 while running flash application

Alright, I know that this error is occurring because of something to do with addchild() function. On frame 2. How do I know? Because when I remove the snippets of code that dynamically place an object onto the stage it works fine. The error is below and the source code for frame 2 is below the error messages.
Error Code
TypeError: Error #1034: Type Coercion failed: cannot convert 0 to flash.display.DisplayObject.
at fl.motion::AnimatorBase/play()
at fl.motion::AnimatorBase$/processCurrentFrame()
at fl.motion::AnimatorBase/handleEnterFrame()
at flash.display::MovieClip/nextFrame()
at Lemonade_fla::MainTimeline/begin()[Lemonade_fla.MainTimeline::frame1:27]
TypeError: Error #1034: Type Coercion failed: cannot convert 0 to
FRAME 2 CODE
flash.display.DisplayObject.
stop();
var guide_tut:guide = new guide();
addChild(guide_tut);
//stand.addEventListener(MouseEvent.CLICK, check);
addEventListener(Event.ENTER_FRAME, check);
function check(ev : Event) : void {
cash.text.text = cash1;
lemons_count.text.text = lemons1;
cups_count.text.text = cups;
straws_count.text.text = straws;
ice_count.text.text = ice;
}
shop_mc.addEventListener(MouseEvent.CLICK, shopnow);
function shopnow(event:MouseEvent):void{
nextFrame();
}
1) I ran your code it works fine, the only place the error could be generated is:
flash.display.DisplayObject.
should be: flash.display.DisplayObject;
but you don't need it.
and
var guide_tut:guide = new guide();
addChild(guide_tut);
I ran it with just an empty mc, it works fine.
2) no reason to have (i know its commented out) but there never a reason to have
stand.addEventListener(MouseEvent.CLICK, check) ever since check is EnterFrame
basically you're error is within either display, most likely you're not extending the class from MovieClip
public class guide extends MovieClip
instead of movieclip it can be sprite or other displayobject...