Flash/Actionscript preloader and button onRelease problem
using this as my actionscript for preloader:
if(_root.getBytesLoaded() != _root.getTotalBytes()) {
gotoAndPlay(1);
}
getting error:
Scene 1, Layer 'Actions', Frame 2, Line 1 1120: Access of undefined property _root.
this is my buttons actionscript:
stop();
home_btn.onRelease = function () {
gotoAndStop(3);
}
page1_btn.onRelease = function (){
gotoAndStop(4);
}
page2_btn.onRelease = function (){
gotoAndStop(5);
}
and error :
Scene 1, Layer 'Actions', Frame 3, Line 2 1119: Access of possibly undefined property onRelease through a reference with static type fl.controls:Button.
开发者_如何学JAVA
id like to get my website working. can you help me guys? what im i doin wrong? id like to use the latest actionscript.
Here is a direct translation of your code to AS3:
Frame 2:
if (root.loaderInfo.bytesLoaded != root.loaderInfo.bytesTotal) {
gotoAndPlay(1);
}
Frame 3:
stop();
home_btn.mouseChildren = page1.mouseChildren = page2.mouseChildren = false;
home_btn.addEventListener(MouseEvent.CLICK, clickHandler);
page1_btn.addEventListener(MouseEvent.CLICK, clickHandler);
page2_btn.addEventListener(MouseEvent.CLICK, clickHandler);
function clickHandler(e:MouseEvent):void {
switch(e.target) {
case home_btn : gotoAndStop(3); break;
case page1_btn : gotoAndStop(4); break;
case page2_btn : gotoAndStop(5); break;
}
}
With that said...I would recommend not loading your assets this way. I would create a "shell" SWF that loads this "main" SWF. This will give you a more accurate load. Also, if you haven't already, start looking into getting your code off of the timeline and into external classes (if you're planning on using AS3). AS3 is an object-oriented programming language and is intended to be used this way. What you have now will work, but learning this method will save you a lot of headaches. Here is a good starting point: http://www.adobe.com/devnet/actionscript/articles/oop_as3.html.
精彩评论