A Flash Developer Resource Site

Results 1 to 3 of 3

Thread: Simple Error #1006: value is not a function problem!

  1. #1
    Random(+123)
    Join Date
    Dec 2008
    Posts
    19

    Cow Icon Simple Error #1006: value is not a function problem!

    Well I'm so close to understanding why this doesn't work.
    First here is the code:
    Code:
    import flash.display.MovieClip;
    
    stage.addEventListener(Event.ENTER_FRAME,updateGame);
    var gameZoneContainer:MovieClip = new MovieClip();
    stage.addChild(gameZoneContainer);
    var ItemSelectedContainer:MovieClip = new MovieClip();
    gameZoneContainer.addChild(ItemSelectedContainer);
    var i:int = 0;
    var frameToCreateObjectOn:int = 24;
    var createItemCounter:int = 0;
    
    var fish:MovieClip = new fish_mc();
    var cookie:MovieClip = new cookie_mc();
    var Items:Array = [fish,cookie];
    var numberOfItems:int = Items.length - 1;
    
    function updateGame(e:Event):void
    {
    	if (i==frameToCreateObjectOn) {
    
    		var ItemSelected:MovieClip = Items[createItemCounter];
    		//var holder:MovieClip=Items[createItemCounter];
    		//Assign a random x position to fish
    		ItemSelected.x = 50 + Math.random() * (480 - 120);
    
    		//Assign the y position to the rectangle
    		ItemSelected.y = 100;
    
    		//Assign a random x and y speed for the rectangle
    		ItemSelected.yspeed = Math.random() * 10 + 5;
    
    		//Add ENTER_FRAME listener for the ItemSelected
    		ItemSelected.addEventListener(Event.ENTER_FRAME, ItemSelectedPositionLoop);
    
    		//Add the ItemSelected to the stage.;
    		ItemSelectedContainer.addChildAt(ItemSelected,0);
    		i = 0;
    		
    		if (createItemCounter==numberOfItems) {
    			createItemCounter = 0;
    		}
    		else {
    			createItemCounter++;
    		}
    	}
    	i++;
    }
    
    function ItemSelectedPositionLoop(e:Event):void
    {
    	//Save the ItemSelected to a local variable
    	var ItemSelected = (Items[createItemCounter])(e.target);
    	
    
    	//Update its position
    	ItemSelected.y +=  ItemSelected.yspeed;
    
    	//Remove the ItemSelected from the stage if it surpasses stage
    	if (ItemSelected.y > stage.stageHeight + 70) {
    		ItemSelected.removeEventListener(Event.ENTER_FRAME, ItemSelectedPositionLoop);
    		ItemSelectedContainer.removeChild(ItemSelected);
    	}
    }
    The error is:
    Code:
    TypeError: Error #1006: value is not a function.
    	at ArrayTest_fla::MainTimeline/ItemSelectedPositionLoop()[ArrayTest_fla.MainTimeline::frame1:102]
    Line 102 is:
    Code:
    var ItemSelected = (Items[createItemCounter])(e.target);
    The problem is to do with:
    Code:
    (Items[createItemCounter])
    If I place "fish_mc" in place of "Items[createItemCounter]", the fish animates but the cookie doesn't. If I put "cookie_mc" instead of "Items[createItemCounter]", the cookie animates but the fish doesn't.

    There feels like there's a simple thing to change but I can't figure it out!

  2. #2
    Senior Member cancerinform's Avatar
    Join Date
    Mar 2002
    Location
    press the picture...
    Posts
    13,449
    The error occurs when a value is converted to a function by for example placing () behind the value. May be you need to eliminate the parentheses in line 102 around e.target.
    - The right of the People to create Flash movies shall not be infringed. -

  3. #3
    Random(+123)
    Join Date
    Dec 2008
    Posts
    19
    Thanks for your reply, it did work although I receive this error:
    Code:
    ArgumentError: Error #2025: The supplied DisplayObject must be a child of the caller.
    The line that this happens in is:
    Code:
    ItemSelectedContainer.removeChild(ItemSelected);
    I understand the error but I don't understand why it's happening when I have added the MovieClip to ItemSelectedContainer.



    I went back however and tried something else out and this worked in a similar way except for another output error.
    I created:
    Code:
    var Items2:Array = [fish_mc,cookie_mc];
    And replaced "Items[createItemCounter]" with "Items2[createItemCounter]" on line 102 so it looked like this:

    Code:
    var ItemSelected = (Items2[createItemCounter])(e.target);
    The ouput error I received from using that is:

    Code:
    TypeError: Error #1034: Type Coercion failed: cannot convert fish_mc@42ff121 to cookie_mc.
    	at ArrayTest_fla::MainTimeline/ItemSelectedPositionLoop()[ArrayTest_fla.MainTimeline::frame1:97]

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