好的 - 希望这是关于flash的最后一篇文章:
我正在尝试在滚动窗格中突出显示文本。 现在我尝试在没有滚动窗格的情况下突出显示它,但问题是相同的,文本会突然显示一小段时间,然后才恢复正常。
我正在使用greensock LoaderMax库将外部swf加载到滚动窗格中。
我正在努力保持简短,但这是如何运作的:
编辑:FULL& CURRENT SRC
package {
import flash.display.MovieClip;
import flash.display.Stage;
//import fl.controls.Button;
import flash.display.SimpleButton;
// javascript call
import flash.external.ExternalInterface;
import flash.text.TextField;
import fl.motion.MotionEvent;
import flash.display.DisplayObject;
import flash.events.MouseEvent;
import fl.containers.ScrollPane;
import fl.events.ScrollEvent;
//important for scrollpane events
import flash.events.Event;
import flash.text.TextSnapshot;
import flash.display.Loader;
import flash.net.URLRequest;
import flash.display.Sprite;
//cursors n' shit
import flash.ui.Mouse;
//debugging
import flash.utils.describeType;
import flash.system.LoaderContext;
import flash.system.ApplicationDomain;
import flash.errors.IOError;
import flash.events.IOErrorEvent;
import flash.display.LoaderInfo;
//timer
import flash.events.TimerEvent;
import flash.utils.Timer;
import flash.utils.*;
/*
importing libraries:
Edit > Preferences > ActionScript > ActionScript 3.0 Settings > Source path
make sure to set path to parent of com folder or whatever
*/
import com.greensock.*;
import com.greensock.loading.*;
import com.greensock.events.LoaderEvent;
import com.greensock.loading.display.*;
import flash.geom.Rectangle;
import flash.display.IBitmapDrawable;
/*
In order to use the line this.addChild(border) your class has to be a display container. movieclip and sprite are the most common to use.
dont forget renaming the class here!
*/
public class expViewer10 extends MovieClip {
var mc2:MovieClip;
var nextPageButton:SimpleButton;
var prevPageButton:SimpleButton;
var jsButton:SimpleButton
var searchButton:SimpleButton;
var firstX:int = 0;
var firstY:int = 0;
var touchDown:Boolean = false;
var startPos:int = 0;
var textPos:int = 0; // aka endPos
var oldStartPos:int = 0;
var oldTextPos:int = 0; // aka endPos
var currentlySelecting:Boolean = false;
var currentText:String = "";
var newSelection:Boolean = false;
var snapshotTrigger:Boolean = false;
// colors
var preSelectionColor:Number = 0xDDAB00;
var selectionColor:Number = 0xFFEF00;
// array of arrays with [0] one selection
// [0][0] id [0][1] startPos ...[2] endPos [3] text
var selectionsArray:Array = new Array();
var theRectangle:DisplayObject;
var markCounter:TextField;
//mcScrollBar.setScrollProperties(1, 1, 4 );
// need to be outside of function
// initialize on enterframe
//var snapTextArray:Array = new Array();
var allSWFLoaded:Boolean = false;
var avoidJumpingMarker:int = 0;
var mc:MovieClip = new MovieClip();;
//addChild(mc);
//addChild(container); // just gotta add containes to stage?
var myLoader:Loader = new Loader(); // create a new instance of the Loader class
var url:URLRequest = new URLRequest("tmp1.swf"); // in this case both SWFs are in the same folder
var bob:Boolean = false;
var captureButton:SimpleButton;
var markUpButton:SimpleButton;
// hack, just initialize once
var dummySprite:Sprite = new Sprite();
//var scrollPane:ScrollPane = scrollPaneOnStage;
var scrollPane:ScrollPane;
var libMC:MovieClip;
var loader:Loader;
var fLoader:forcibleLoader;
var queue:LoaderMax;
var markUpQueue:LoaderMax;
var loaderArray:Array;
var mcArray:Array;
var mcArrayTest:Array = new Array();
//
var offSetArray:Array;
var currentClip:int;
var snapText:TextSnapshot;
var snapTextArrayOffset:Array = new Array();
var inter:int = 0;
var noPages:int = 0;
var pagesLoaded = 0;
var justAMovieClip:MovieClip;
// renanme this as well!
public function expViewer10() {
// wait till this class has been added to the stage!
this.addEventListener(Event.ADDED_TO_STAGE, attachButtonsNStuff);
// dont use this, button should be there already
//addChild(nextPageButton);
//attachButtonsNStuff();
}
private function attachButtonsNStuff(evt:Event):void {
//scrollPane = new ScrollPane();
//addChild(scrollPane);
// constructor code
queue = new LoaderMax({name:"mainQueue", onProgress:progressHandler, onComplete:checkHandler, onError:onError});
//this.addEventListener(Event.ENTER_FRAME, onEnterFrame);
//MovieClip(root).gotoAndStop(1);
mc.gotoAndStop(1);
loadPages();
}
private function progressHandler(event:LoaderEvent):void {
//trace("progress: " + event.target.progress);
}
private function onError(event:LoaderEvent) {
// trace("error occured with " + event.target + ": " + event.text);
}
private function checkHandler(event:LoaderEvent):void {
displayPages();
MovieClip(root).addChild(mc);
//mcArray[0].textSnapshot.setSelected( 4, 300, true );
//queue.getContent( ("tmp1") ).rawContent.textSnapshot.setSelected( 4, 300, true );
setTimeout ( function ( libMC:MovieClip ) : void {
try {
libMC.textSnapshot.setSelectColor( 0xFF0000 );
libMC.textSnapshot.setSelected( 100, 200, true );
} catch (error:Error) {
trace(error.message);
} finally {
trace("tada");
}
},
5000,
mcArray[0]
);
}
private function loadPages():void {
try{
noPages = 12;
for (var i:int = 0 ; i < noPages ; i++){
queue.append( new SWFLoader("tmp"+(i+1)+".swf", {name:"tmp"+(i+1), container:mc, estimatedBytes:70000, autoPlay:false, autoDispose:false}) );
}
queue.load();
} catch (error:Error) {
// statements
//ExternalInterface.call("window.alert(\"load err: "+error.message+"\")");
} finally {
// statements
}
}
private function displayPages():void {
//trace('1');
mcArray = new Array();
offSetArray = new Array();
var fromTop:Number = 0;
var totalChars:int = 0;
//ExternalInterface.call("window.alert(\"length err: "+loaderArray.length.toString()+"\")");
for (var i:int=0 ; i < 12 ; i++) {
//var tempmc:MovieClip =
//justAMovieClip = MovieClip(queue.getContent( ("tmp"+(i+1)) ).rawContent);
mcArray[i] = queue.getContent( ("tmp"+(i+1)) ).rawContent;
var rect:Rectangle = mcArray[i].getRect(this);
//trace(inter++);
//mc.addChild(mcArray[i]);
mcArray[i].gotoAndStop(1);
mc.getChildAt(i).y = fromTop;
offSetArray.push(fromTop);
fromTop += rect.height + 10; // margin - put on top
totalChars += mcArray[i].textSnapshot.charCount;
//ExternalInterface.call("window.alert(\"tot chars: "+totalChars+"\")");
snapTextArrayOffset.push(totalChars);
}
}
}
}
答案 0 :(得分:2)
也许您应该在设置颜色之前gotoAndStop
使用MovieClip ,否则第一个关键帧可能会重置文本。另外,请尝试使用gotoAndStop(1);
。 MovieClip上不存在0帧。
修改强>
我记得有些组件可能会有一些延迟的启动例程。试试这个:
function checkHandler(event:LoaderEvent):void {
try {
libMC = LoaderMax.getContent("childClip").rawContent as MovieClip;
scrollPane.source = libMC;
libMC.gotoAndStop(1);
setTimeout ( function ( libMC:MovieClip ) : void {
libMC.textSnapshot.setSelectColor( 0xFF0000 );
libMC.textSnapshot.setSelected( 100, 200, true );
},
100,
libMC
);
} catch (error:Error) {
// statements
ExternalInterface.call("window.alert(\"error: "+error.message+"\")");
} finally {
// statements
}
}
}