A Flash Developer Resource Site

Results 1 to 2 of 2

Thread: [RESOLVED] call as file to addChild from Library

  1. #1
    Member
    Join Date
    Nov 2004
    Location
    London, Covent Garden
    Posts
    78

    resolved [RESOLVED] call as file to addChild from Library

    Hi,

    I'm just starting out in as3 and for the life of me can not see how to create an instance on the stage of a symbol in the library by calling a function which resides in as file.

    My library symbol has linkage (Class: newsButton, Base class: flash.display.MovieClip)

    On the timeline in the fla file I know how to create an instance of it:
    Code:
    //add news buttons to the stage
    var _newsButton:newsButton = new newsButton();
    addChild(_newsButton);
    _newsButton.x = 66;
    _newsButton.y = 287;
    What I'd like to do instead is place a function on the timeline called newsButton() that will read from a package where the function is defined (as file) and here's where I'm at:

    On the timeline:
    Code:
    import com.bosie.*;
    newsButton();
    AS file in directory com.bosie:
    Code:
    package com.bosie {
    	import flash.display.MovieClip;
    
    	public class newsButton extends MovieClip {
    		private var _newsButton:newsButton;
    		public function newsButton() {
    			_newsButton = new newsButton();
    			trace('newsButton() function called');
    			addChild(_newsButton);
    			_newsButton.x = 66;
    			_newsButton.y = 287;
    		}
    	}
    }

    The problem is, when I run the movie I get:
    "Incorrect number of arguments. Expected 1"

    Have I got this completely backwards or which arguments do I need to pass in the function?
    Last edited by bosie; 05-24-2008 at 04:11 AM.
    bosie

  2. #2
    Member
    Join Date
    Nov 2004
    Location
    London, Covent Garden
    Posts
    78
    I solved my problem by replacing newsButton() on the timeline with addChild(new newsButton);

    I think i had some ambiguity going on as well, too many items named newsButton so here's the working code:

    I have a symbol in fla library with linkage (Class: news, Base class: flash.display.MovieClip)

    On the timeline:
    Code:
    import com.bosie.*;
    addChild(new newsButton); //the name of the class file
    AS file:
    Code:
    package com.bosie {
    	import flash.display.Sprite;
    	import flash.events.MouseEvent;
    
    	public class newsButton extends Sprite {
    		private var _newsButton:news;
    		public function newsButton() {
    			init();
    		} //end function addNewsButton
    		private function init() {
    			_newsButton = new news();
    			trace('newsButton() function called');
    			addChild(_newsButton);
    			_newsButton.x = 66;
    			_newsButton.y = 287;
    			_newsButton.buttonMode = true;
    			_newsButton.addEventListener(MouseEvent.CLICK, shrinkNews);
    		} //end private function init()
    		private function shrinkNews(event:MouseEvent):void {
    			_newsButton.scaleX = 0.6;
    			_newsButton.scaleY = 0.6;
    		} //end private function shrinkNews
    	} //end class newsButton
    } //end package
    bosie

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