English 中文(简体)
当脚本第一次在动作脚本中运行时如何禁用按钮
原标题:how to disable button when the script runs first time in action script

我有动作脚本包包游戏, 我希望当页面加载到当前包包时, 添加到当前包包时被禁用, 点击新包加到新包包时它应该被激活, 这里点击的是游戏脚本中的包包游戏所使用的代码 。

""https://i.sstatic.net/Qyngc.jpg" alt="此处输入图像描述"/ >

显示图像时, 显示的图像第一次添加到当前包包时, 按到新包添加后, 第一次应该不活动, 然后应该激活

    package {
import com.greensock.loading.LoaderMax;
import com.greensock.loading.XMLLoader;
import com.greensock.loading.ImageLoader;

import com.greensock.TimelineLite;
import com.greensock.TweenMax;

import com.greensock.events.LoaderEvent;

import com.greensock.plugins.TweenPlugin;
import com.greensock.plugins.GlowFilterPlugin;
import com.greensock.plugins.BlurFilterPlugin;

import appkit.responders.NResponder;

import bdesignet.utilities.keepRatio;

import flash.display.MovieClip;
import flash.display.StageAlign;    
import flash.display.StageScaleMode;

import flash.display.BitmapData;
import flash.display.Bitmap;

import flash.net.URLRequest;
import flash.net.navigateToURL;

import flash.events.MouseEvent;
import flash.events.TimerEvent;

import flash.utils.Timer;

public class main extends MovieClip {
    private var _controlsTimeline:TimelineLite = new TimelineLite( { paused:true, onComplete:startGame 时 时 );
    private var _scoreTimeline:TimelineLite = new TimelineLite( { paused:true, onComplete:enableReplay, onReverseComplete:startGame 时 时 );

    private var _loadermainXML:XMLLoader = new XMLLoader("", { name:"mainXML", onComplete:onmainDataLoaded 时 时 );

    private var _files:LoaderMax;

    private var _glowCurrentBag:TweenMax;
    private var _glowNewBag:TweenMax;
    private var _glowReplay:TweenMax;

    private var _glowPicture:TweenMax;

    private var _xmlData:XML;

    private var _currentBagClicked:NResponder;
    private var _newBagClicked:NResponder;

    private var _replayOver:NResponder;
    private var _replayOut:NResponder;
    private var _replayClicked:NResponder;

    private var _currentItem:uint = 0;
    private var _currentBag:uint = 0;
    private var _currentBagItems:uint = 0;
    private var _currentBagType:String = "";
    private var _points:int = 0;

    private var _image:Bitmap = new Bitmap();

    private var _started:Boolean = false;

    private var _start:Date;
    private var _end:Date;

    private var _hours:Number = new Number;
    private var _minutes:Number = new Number;
    private var _seconds:Number = new Number;
    private var _totalTime:Number = new Number;

    private var _counterTimer:Timer = new Timer(1000);
    private var _counterTimerEvent:NResponder;

    TweenPlugin.activate([GlowFilterPlugin, BlurFilterPlugin]);

    public function main():void {
        score.alpha = 0;

        stage.align = StageAlign.TOP_LEFT;
        stage.scaleMode = StageScaleMode.NO_SCALE;

        _loadermainXML.url = "items.xml";

        _loadermainXML.load();
    时 时
    private function onmainDataLoaded(event:LoaderEvent):void {
        _xmlData = XML(_loadermainXML.content);

        _files = new LoaderMax( { name:"files", onComplete:onFilesLoaded, onProgress:onFilesProgress 时 时 );

        _glowCurrentBag = TweenMax.to(controls.addCurrentBag, 1, { glowFilter: { color:0xF7E9CF, alpha:.8, blurX:16, blurY:16 时 时, timeScale:2, paused:true 时 时 );
        _glowNewBag = TweenMax.to(controls.addNewBag, 1, { glowFilter: { color:0xF7E9CF, alpha:.8, blurX:16, blurY:16 时 时, timeScale:2, paused:true 时 时 );
        _glowReplay = TweenMax.to(score.replay, 1, { glowFilter: { color:0x695532, alpha:.8, blurX:16, blurY:16 时 时, timeScale:2, paused:true 时 时 );

        _glowPicture = TweenMax.to(_image, 1, { blurFilter: { blurX:20, blurY:20 时 时, alpha:0, timeScale:2, paused:true, onComplete:showItem, onReverseComplete:enableClicks 时 时 );

        for (var i:uint = 0; i < _xmlData.images.image.length(); i++ ) {
            _files.append( new ImageLoader(_xmlData.images.@folder + _xmlData.images.image[i].@url, { name:"image_" + i 时 时) );
        时 时
        _files.load();


    时 时
    private function onFilesProgress(event:LoaderEvent):void {
        loader.value_txt.text = String(Math.round(event.target.progress * 100)) + " %";
    时 时
    private function onFilesLoaded(event:LoaderEvent):void {
        controls.numberBags.numberBags_txt.text = String(_currentBag);
        controls.remainingText.value_txt.text = String(_xmlData.images.image.length() - 1);

        _replayOver = NResponder.addNative(score.replay, MouseEvent.MOUSE_OVER, onOverReplay);
        _replayOut = NResponder.addNative(score.replay, MouseEvent.MOUSE_OUT, onOutReplay);
        _replayClicked = NResponder.addNative(score.replay, MouseEvent.CLICK, onClickedReplay);
        _replayClicked.paused = true;
        _replayOver.paused = true;
        _replayOut.paused = true;

        NResponder.addNative(controls.addCurrentBag, MouseEvent.MOUSE_OVER, onOverCurrentBag);
        NResponder.addNative(controls.addCurrentBag, MouseEvent.MOUSE_OUT, onOutCurrentBag);
        _currentBagClicked = NResponder.addNative(controls.addCurrentBag, MouseEvent.CLICK, onClickedCurrentBag);
        _currentBagClicked.paused = true;

        NResponder.addNative(controls.addNewBag, MouseEvent.MOUSE_OVER, onOverNewBag);
        NResponder.addNative(controls.addNewBag, MouseEvent.MOUSE_OUT, onOutNewBag);

        _newBagClicked = NResponder.addNative(controls.addNewBag, MouseEvent.CLICK, onClickedNewBag);
        _newBagClicked.paused = true;

        controls.addCurrentBag.buttonMode = true;
        controls.addNewBag.buttonMode = true;

        NResponder.addNative(score.emailLink, MouseEvent.CLICK, onLinkClick);
        score.emailLink.buttonMode = true;

        imageContainer.addChild(_image);

        _counterTimerEvent = NResponder.addNative(_counterTimer, TimerEvent.TIMER, onCounterTimer);
        _counterTimerEvent.paused = true;

        _controlsTimeline.append(TweenMax.to(loader, 1, { alpha:0, timeScale:2 时 时 ));
        _controlsTimeline.append(TweenMax.to(controls.addCurrentBag, 1, { alpha:1, x:237, timeScale:2 时 时 ));
        _controlsTimeline.append(TweenMax.to(controls.addNewBag, 1, { alpha:1, x:237, timeScale:2 时 时 ), -0.5);
        _controlsTimeline.append(TweenMax.to(controls.currentBag, 1, { alpha:1, y:280, timeScale:2 时 时 ));
        _controlsTimeline.append(TweenMax.to(controls.numberBags, 1, { alpha:1, y:280, timeScale:2 时 时 ), -0.5);
        _controlsTimeline.append(TweenMax.to(controls.remainingText, 1, { alpha:1, timeScale:2 时 时 ));
        _controlsTimeline.append(TweenMax.to(controls.timeText, 1, { alpha:1, timeScale:2 时 时 ));

        _scoreTimeline.append(TweenMax.to(controls.timeText, 1, { alpha:0, timeScale:2 时 时 ));
        _scoreTimeline.append(TweenMax.to(controls.remainingText, 1, { alpha:0, timeScale:2 时 时 ));
        _scoreTimeline.append(TweenMax.to(controls.numberBags, 1, { alpha:0, y:416, timeScale:2 时 时 ));
        _scoreTimeline.append(TweenMax.to(controls.currentBag, 1, { alpha:0, y:416, timeScale:2 时 时 ), -0.5);
        _scoreTimeline.append(TweenMax.to(controls.addNewBag, 1, { alpha:0, x:467, timeScale:2 时 时 ));
        _scoreTimeline.append(TweenMax.to(controls.addCurrentBag, 1, { alpha:0, x:467, timeScale:2 时 时 ), -0.5);
        _scoreTimeline.append(TweenMax.from(score, 1, { blurFilter: { blurX:20, blurY:20 时 时, alpha:0, timeScale:2 时 时 ));
        _scoreTimeline.append(TweenMax.to(score, 1, { alpha:1, timeScale:2 时 时 ), -0.5);

        _controlsTimeline.play();
    时 时
    private function onLinkClick(e:MouseEvent):void {
        var request:URLRequest = new URLRequest("mailto:[email protected]" + "?subject=Score&body=Score%20:%20" + _points + "
Date%20:%20" + (_end.month + 1) + "/" + _end.date + "/" + _end.fullYear);
        //trace(request.url);
        navigateToURL(request, "_blank");
    时 时
    private function onCounterTimer(e:TimerEvent):void {
        _end = new Date();
        controls.timeText.value_txt.text = returnTimeString(Math.round((_end.time - _start.time) / 1000));
    时 时
    private function startGame():void {

        _start = new Date();

        _counterTimerEvent.paused = false;
        _counterTimer.start();

        _currentItem = 0;
        _points = 0;
        _currentBag = 0;
        _currentBagItems = 0;

        _currentBagType = _xmlData.images.image[0].@bag_type;

        showItem();

        !_started ? (TweenMax.from(_image, 1, { blurFilter: { blurX:20, blurY:20 时 时, alpha:0, onComplete:enableClicks 时 时 ), _started = true):void;
    时 时
    private function onOverReplay(e:MouseEvent):void {
        _glowReplay.play()
    时 时
    private function onOutReplay(e:MouseEvent):void {
        _glowReplay.reverse();
    时 时
    private function onClickedReplay(e:MouseEvent):void {
        _replayClicked.paused = false;
        _replayOver.paused = false;
        _replayOut.paused = false;

        controls.numberBags.numberBags_txt.text = 0;
        controls.remainingText.value_txt.text = String(_xmlData.images.image.length() - 1);
        controls.currentBag.currentItems_txt.text = "";

        controls.timeText.value_txt.text = "00:00";

        _scoreTimeline.reverse();
    时 时
    private function onOverCurrentBag(e:MouseEvent):void {
        _glowCurrentBag.play();
    时 时
    private function onOutCurrentBag(e:MouseEvent):void {
        _glowCurrentBag.reverse();
    时 时
    private function onClickedCurrentBag(e:MouseEvent):void {
        _xmlData.images.image[_currentItem].@bag_type != _currentBagType ? _points-=2 : _points+=2;

        _currentBagItems > 0 ? controls.currentBag.currentItems_txt.appendText(", ") : controls.currentBag.currentItems_txt.text = "";
        controls.currentBag.currentItems_txt.appendText(_xmlData.images.image[_currentItem].@name);
        _currentBagItems++;
        nextItem();
    时 时
    private function onOverNewBag(e:MouseEvent):void {
        _glowNewBag.play();
    时 时
    private function onOutNewBag(e:MouseEvent):void {
        _glowNewBag.reverse();
    时 时
    private function onClickedNewBag(e:MouseEvent):void {
        _xmlData.images.image[_currentItem].@bag_type != _currentBagType ? _points++ : _points--;

        _currentBagType = _xmlData.images.image[_currentItem].@bag_type;
        _currentBagItems = 1;
        _currentBag++;
        controls.numberBags.numberBags_txt.text = String(_currentBag);
        controls.currentBag.currentItems_txt.text = _xmlData.images.image[_currentItem].@name;

        nextItem();
    时 时
    private function nextItem():void {
        _currentItem++;

        _currentBagClicked.paused = true;
        _newBagClicked.paused = true;

        _glowPicture.restart();
    时 时
    private function enableReplay():void {
        _replayClicked.paused = false;
        _replayOver.paused = false;
        _replayOut.paused = false;

        score.replay.buttonMode = true;

    时 时
    private function enableClicks():void {
        _currentBagClicked.paused = false;
        _newBagClicked.paused = false;
    时 时
    private function showItem():void {
        if (_currentItem < _xmlData.images.image.length()) {
            controls.remainingText.value_txt.text = String(_xmlData.images.image.length() - (_currentItem + 1));

            _image.bitmapData = LoaderMax.getLoader("image_" + _currentItem).rawContent.bitmapData;

            keepRatio.findValues(_image.height, _image.width, 268, 390, true);

            _image.x = keepRatio.newX;
            _image.y = keepRatio.newY;
            _image.height = keepRatio.newHeight;
            _image.width = keepRatio.newWidth;
            _glowPicture.currentProgress == 1 ? _glowPicture.reverse() : null;
        时 时else {
            //_end = new Date();

            _counterTimerEvent.paused = true;
            _counterTimer.stop();

            score.text.total_txt.text = String(_xmlData.images.@total_score);
            score.text.value_txt.text = String(_points);
            score.timeText.value_txt.text = returnTimeString(Math.round((_end.time - _start.time) / 1000));

            _scoreTimeline.play();
        时 时
    时 时
    public function returnTimeString($val:Number):String{
        _hours = Math.floor($val/3600);
        _minutes = Math.floor($val/60);
        _seconds = Math.floor($val-(_minutes*60));
        return (_hours > 0 ? String(_hours) +  :  :    ) + (_minutes > 9 ?       String(_minutes) :  0  + String(_minutes)) +  :  + (_seconds > 9 ? String(_seconds) :  0  + String(_seconds));
    时 时
时 时

时 时

问题回答

Don t add the eventListener for add to current bag immediately. Create a boolean (ie newBagPressed = false). When Add to new bag is pressed, test for the boolean. If it is false, set it to true and only then add the eventListener to Add to current bag.

希望这能帮助:)





相关问题
Disable button tooltip in AS3

I want to disable the tooltip on certain buttons. The tooltip manager seems to be an all or nothing solution. Is it possible to disable the tooltip for just one or two buttons?

Sorting twodimensional Array in AS3

So, i have a two-dimensional Array of ID s and vote count - voteArray[i][0] = ID, voteArray[i][1] = vote count I want the top 3 voted items to be displayed in different colors, so i have a 2nd Array -...

Virtual Tour using sketch up, ajax, flash technologies

I want to know if there are existing technology that make your 3d models in sketch into virtual tours, using either Ajax or Flash for web presentation. If there s none, which will be a good approach ...

AS3 try/catch out of memory

I m loading a few huge images on my flex/as3 app, but I can t manage to catch the error when the flash player runs out of memory. Here is the what I was thinking might work (I use ???? because i dont ...

Red5 Security Tutorial

I am looking for a step by step tutorial on securing Red5 from intrusion. This seems to be a question that comes up alot in a google search, but is never really answered in a way that makes sense to ...

Clipboard access using Javascript - sans Flash?

Is there a reliable way to access the client machine s clipboard using Javascript? I continue to run into permissions issues when attempting to do this. How does Google Docs do this? Do they use ...

visible property of DisplayObject

For example I have a hierarchy of movie clips. mc1 is a child of mc, and mc2 is a child of mc1. Turns out that when I set mc1.visible = false; mc2.visible stays true. Is that supposed to happen?...

热门标签