Please help me solve this actionscript 3 Error 1067 - actionscript-3

Please help me correct my mistake. I received this Error:
1067: Implicit coercion of a value of type of void to an unrelated type flash.display:MovieClip.
import flash.events.Event;
import flash.display.MovieClip;
var vidLc:MovieClip = null;
var vidLc1:MovieClip;
//--Play Count MovieClip
function countingPlay():void
{
vidLc = new CountingVid();
//--
vidLc1 = vidLc.play();
//--
addChild(vidLc1);
vidLc1.x = -1.80;
vidLc1.y = 2.10;
}
//-- stop count MovieClip
function countingStop():void
{
if (vidLc){
vidLc1.stop();
removeChild(vidLc1);
vidLc = null;
}
}

According to your posted code, that error comes from this line :
vidLc1 = vidLc.play();
Here you are using the MovieClip.play() function on your vidLc MovieClip (vidLc.play()), which did return nothing, to initialize your vidLc1 MovieClip, and that's why the error #1067 is fired, but in the case where you've overridden that function in your CountingVid class, then it should return a MovieClip object.
Hope that can help.

Related

event.bytesLoaded - Access of undefined property event

1120: Access of undeined property event.
...is thrown for both event.bytesLoaded and event.bytesTotal
public class Main extends MovieClip {
public function Main() {
system_load.bar.scaleX = 0;
this.stage.addEventListener(Event.ENTER_FRAME, this._loadUpdate);
}
private function _loadUpdate( e:Event ):void {
var bl:int = event.bytesLoaded;
var bt:int = event.bytesTotal;
system_load.bar.scaleX = (bl/bt);
}
}
I'm unsure of what to import to make this work. Currently has the following imported:
import flash.display.MovieClip;
import flash.events.Event;
import flash.events.MouseEvent;
import flash.events.ProgressEvent;
Just ask and I'll provide with more details.
The reason you are getting this error is because the listener you added is using an Event type and not a ProgressEvent. The ProgressEvent class has the properties bytesLoaded and bytesTotal, whereas the Event class does not. What you are looking for is usage of the ProgressEvent.PROGRESS. An example would be:
myLoader.contentLoaderInfo.addEventListener( ProgressEvent.PROGRESS, loadUpdate );
Although your current implementation is not actually loading anything because you added the listener to the stage and not a loader, so the progress would not be displayed. For relevant examples check out the ProgressEvent class here:
http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/events/ProgressEvent.html#includeExamplesSummary
Here's a quick and dirty example I put together loading an image:
var myLoader:Loader = new Loader();
myLoader.contentLoaderInfo.addEventListener( ProgressEvent.PROGRESS, loadUpdate );
myLoader.load( new URLRequest("path/to/image.png") );
Then you could just use your loadUpdate() as is.
your event variable is called e and not event. Try:
private function _loadUpdate( event:ProgressEvent ):void {
var bl:Number = event.bytesLoaded;
var bt:Number = event.bytesTotal;
system_load.bar.scaleX = (bl/bt);
}
Edit: i suggest you to use ProgressEvent if you want to access to bytesLoaded and bytesTotal

TypeError: Error #2007 Parameter type must be non-null

I have this problem :
TypeError: Error #2007: Parameter type must be non-null. at
flash.events::EventDispatcher/addEventListener() at Ch05_02()
when I am running my flash doc the Ch05_02 as file
package {
import it.gotoandplay.smartfoxserver.SmartFoxClient;
import it.gotoandplay.smartfoxserver.SFSEvent;
import it.gotoandplay.smartfoxserver.SFSEvent.onJoinRoom;
import it.gotoandplay.smartfoxserver.data.Room;
import it.gotoandplay.smartfoxserver.data.User;
import flash.display.*;
public class Ch05_02 extends MovieClip{
private var _sfs:SmartFoxClient;
private var _avatarList:Array = new Array();
public function Ch05_02() {
_sfs = new SmartFoxClient(true);
_sfs.addEventListener(SFSEvent.CONNECTION, onConnection);
_sfs.addEventListener(SFSEvent.ROOM_JOIN, onJoinRoom);
_sfs.addEventListener(SFSEvent.USER_ENTER_ROOM, onUserEnterRoom);
_sfs.addEventListener(SFSEvent.USER_EXIT_ROOM, onUserLeaveRoom);
_sfs.connect("127.0.0.1",9339);
}
private function onConnection(e:SFSEvent):void
{
var ok:Boolean = e.params.success;
if (ok){
_sfs.login("simpleChat","myname","");
}
}
private function onRoomListUpdate(e:SFSEvent):void
{
_sfs.autoJoin();
}
}
}
Looking at the documentation for SmartFox, it appears that you have the event names wrong. That's why the compiler is complaining about the type parameter being null. SFSEvent.CONNECTION, SFSEvent.ROOM_JOIN, et al do not exist and are therefore null.
You'll want to use the correct event names. SFSEvent.onConnection, SFSEvent.onJoinRoom, etc.

1067: Implicit coercion of a value of type void to an unrelated type Function

So I'm having a few noob errors to my actionscript and I need some help in resolving it as I keep. The code implements a Timer change will change text for a given duration. It received the duration and the RichText item that need to be highlighted/changed and changes it's color for a given time. That's the basic structure of it.
package
{
import flash.events.Event;
import flash.events.TimerEvent;
import flash.utils.Timer;
import spark.components.RichText;
public class TextChanger
{
public function changeColorForDuration(Duration:int, Texter:RichText){
var highlightTextForDuration:Timer = new Timer(1000, Duration);
highlightTextForDuration.addEventListener(TimerEvent.TIMER_COMPLETE, textDehighlight(Texter));
textHighlight(Texter);
highlightTextForDuration.start();
}
private function textHighlight(specificText:RichText):void{
var textField:RichText = specificText;
textField.setStyle("color", "#ED1D24");
}
private function textDehighlight(textToChange:RichText):void{
var textField:RichText = textToChange;
textField.setStyle("color", "#00000");
}
}
}
Any assistance you can offer will be greatly appreciated.
Thanks.
When you call addEventListener, you need to pass in a function, not a function call:
highlightTextForDuration.addEventListener(TimerEvent.TIMER_COMPLETE, textDehighlight);
And your listener function needs to look more like this:
private function textDehighlight(e:TimerEvent):void{
var textField:RichText = textToChange;
textField.setStyle("color", "#00000");
}
Of course, that will require that you put a class variable for textToChange. If that doesn't work, you can use an anonymous listener function:
highlightTextForDuration.addEventListener(TimerEvent.TIMER_COMPLETE, function(e:TimerEvent):void {
var textField:RichText = Texter;
textField.setStyle("color", "#00000");
});

Actionscript 3: Class constructor in function variable?

I want to make a variable hold a class constructor, but it gives this error:
var myFunction:Function
function someFunction() {}
myFunction = someFunction //works
myFunction = MovieClip //doesn't work - 1067: Implicit coercion of a value of type Class to an unrelated type Function.
Is there a way to do it?
The correct type to hold a class is Class, not Function.
var myClass:Class = MovieClip;

As3 Vector<T> parametric TYPE

I have one vector instance and I'm exporting swf with Flash Player 10/10.1.
I want initialise it with a parametric type. I tried as follow:
var someType:Class = MyCustomClass;
var v:Vector.<someType> = new Vector.<someType>();
But it doesn't work!!
There is a way to do this?
I hope question is clear :-)
Thanks in advance!
someType is the instance of the class type; whereas Vector is a container of that type.
This should be:
var v:Vector.<MyCustomClass> = new Vector.<MyCustomClass>();
Otherwise, I've noticed Haxe would compile this as:
var v:Vector.<Object> = new Vector.<Object>();
Flash polymorphism is lacking, if you had class A and class B, and attempted to push them to a vector of type Class you would receive an error:
Example
package
{
import flash.display.Sprite;
public class test extends Sprite
{
public function test()
{
var v:Vector.<Class> = new Vector.<Class>();
var a:A = new A();
var b:B = new B();
v.push(a);
v.push(b);
}
}
}
Error:
TypeError: Error #1034: Type Coercion failed: cannot convert A#43a2ff1 to Class.
Jason's right. You can't do this. I'm sorry. I ran into the same problem a while back.
Dynamically instantiate a typed Vector from function argument?
Sucks, doesn't it? :-)