惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

Recent Commits to openclaw:main
Recent Commits to openclaw:main
L
LangChain Blog
月光博客
月光博客
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
博客园 - 【当耐特】
宝玉的分享
宝玉的分享
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
Last Week in AI
Last Week in AI
人人都是产品经理
人人都是产品经理
博客园_首页
T
Tailwind CSS Blog
P
Proofpoint News Feed
雷峰网
雷峰网
D
Darknet – Hacking Tools, Hacker News & Cyber Security
IT之家
IT之家
V
Vulnerabilities – Threatpost
阮一峰的网络日志
阮一峰的网络日志
C
CERT Recently Published Vulnerability Notes
Attack and Defense Labs
Attack and Defense Labs
S
Schneier on Security
Security Archives - TechRepublic
Security Archives - TechRepublic
L
Lohrmann on Cybersecurity
V
Visual Studio Blog
云风的 BLOG
云风的 BLOG
WordPress大学
WordPress大学
The Register - Security
The Register - Security
N
Netflix TechBlog - Medium
Hugging Face - Blog
Hugging Face - Blog
Project Zero
Project Zero
博客园 - 叶小钗
F
Full Disclosure
大猫的无限游戏
大猫的无限游戏
Latest news
Latest news
S
SegmentFault 最新的问题
C
Cyber Attacks, Cyber Crime and Cyber Security
Google Online Security Blog
Google Online Security Blog
Recorded Future
Recorded Future
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
Hacker News - Newest:
Hacker News - Newest: "LLM"
腾讯CDC
L
LINUX DO - 最新话题
Google DeepMind News
Google DeepMind News
P
Privacy International News Feed
I
InfoQ
F
Fortinet All Blogs
Vercel News
Vercel News
H
Hackread – Cybersecurity News, Data Breaches, AI and More
T
Threatpost
T
Tenable Blog
B
Blog RSS Feed

MarcySutton.com RSS Feed

On Joining Khan Academy Developing anti-SLAPP policies for A11y Slack with Harvard Cyberlaw Clinic Focus on What Matters Celebrating One Year of Independence as Modern Sole Design, LLC Evinced is Pushing the Limits of Automated Accessibility Testing Content-visibility and Accessible Semantics Finding accessibility jobs in specialized companies and the mainstream Outsider Leverage and Accessibility Encouraging Open Source Contributions with Docs: a Self-Fulfilling Prophecy Remote Work and Van Life Salary and Career Growth Prototype Testing for Accessible Client-Side Routing On Great Leadership, Gatsby & Girl Develop It The Deal with Developer Advocacy Live Coding Accessibility Chapter Two at Deque 2017, in Music Writing winning abstracts Accessibility is a Civil Right 2016, a Year of Milestones Best of 2016 Music Links vs. Buttons in Modern Web Applications Accessibility and Performance I won an O Web Accessibility Resources This is what a developer looks like. What Wally On writing better captions for images What I’ve Learned Working on a Large Open-Source Framework Speak at your local elementary school. Button Focus Hell Page Scrolling in Mobile Safari & VoiceOver Accessibility Wins Notes from CSUN 2015 Protractor Accessibility Plugin Riding a bicycle to an accessibility conference 2014: One to Remember AngularJS Material Design & ngAria Summing Up JSConf EU 2014 How I Audit a Website for Accessibility Accessibility and the Shadow DOM: JSConf Australia 2014 CSUN 2014 Conference Recap Accessibility and the Shadow DOM Favorite Music 2013 Girl Develop It Web Accessibility Mobile Web Accessibility with VoiceOver Webstock & NZ 2013 Favorite Music 2012 Target Corporate Site Redesign: Accessible & Responsive Web Development Decibel Festival Recap 2012 Favorite Music 2011 Spiceboard: Wordpress Recipes for iPad POP Clock Favorite Music 2010 CSS + JS + Accessibility Christmas JS1k Zend Framework. NACCC Urban Type Sutton RV Simplexml in php 5 AS3 Mouse Events Holiday 2009 Why Outlook Sucks
AS3 Load Workflow
2010-02-17 · via MarcySutton.com RSS Feed

February 17, 2010

I recently finished my first big Actionscript 3 website and had to decide on the best loading sequence. I initially tried using the BulkLoader Class, since filesize wasn’t much of an issue, but I ran into trouble when I needed to add things to the queue after loading began.

I was trying to load multiple external assets at once (1 swf, 1 css file, multiple images), but couldn’t quite figure out how to order the sequence because of the dependency on a loaded XML file. I posed this question:

What are the best practices for program initialization and chain loading of assets in AS3, particularly when the site structure is created from an XML file?

First and foremost, I was loading a single SWF and an XML file containing the navigation / page structure, page id’s, page content, and slideshow image filenames. I tried using the Bulk-Loader class to load the XML and a CSS file up front, and then loaded all images while populating the site. It was a multi-part process: download xml, assign page instances, load images and text formatted via CSS, and show page 0. I wondered: was there a way to somehow use a single preloader for all of this bulk-loading?

A few notes about my initialization process: there was 1 frame in the timeline, and only the preloader existed on the stage. The contents of the website (navigation, pages, subpages, background images, slideshows, etc.) were all initialized as new objects based on the loaded XML, next removing the preloader clip and starting the movie. I was also implementing SWFAddress, so the preloading sequence was critical to master.

I luckily discovered AS3 QueueLoader — it enabled me to add assets to the queue on the fly after the XML was loaded, and still kept my preloading as one process. Sweet!

I hope this helps somebody. Let me know if you have any questions about it!

Here is some code that adds images to the queue after the XML has loaded (a lot of details omitted):

 
private function init():void {
    _oLoader = new QueueLoader();
    _oLoader.addItem(PATH+cssURL, css, {title:'cssContent'});
    _oLoader.addItem(PATH+"xml/copy.xml", pageXML, {title:'pageXML'});
    _oLoader.addEventListener(QueueLoaderEvent.ITEM_PROGRESS, onItemProgress, false, 0, true);
    _oLoader.addEventListener(QueueLoaderEvent.ITEM_COMPLETE, onItemComplete, false, 0, true);
    _oLoader.addEventListener(QueueLoaderEvent.QUEUE_PROGRESS, onQueueProgress, false, 0, true);
    _oLoader.addEventListener(QueueLoaderEvent.QUEUE_COMPLETE, onQueueComplete, false, 0, true);
    _oLoader.execute();
}
 
private function onItemComplete(evt:QueueLoaderEvent):void {
    if (evt.title == 'cssContent') {
        css = StyleSheet(evt.content);
    }
 
    if(evt.title == 'pageXML'){
        pageXML = XML(evt.content);
        processXML(); // creates page objects based on XML
 
        for(var i:int=0; i<pageXML.PARENT.length(); i++) {
           //loops through XML for background images and adds them to various
           //sprite layers for simple turning on and off
 
          numSubPages = pageXML.PARENT[i].PAGE.length();
          var pageImgHolder = new Sprite();
          pageImgHolder.name = 'page'+i;
          pageImgHolder.x = 0; pageImgHolder.y = 0;
          bgImgHolder_mc.addChild(pageImgHolder);
 
          for(var j:int=0; j<numSubPages; j++) {
              if(String(pageXML.PARENT[i].PAGE[j].@IMAGE) !== '') {
                  bgImg = new Sprite();
                  bgImg.name = 'page'+i+'img'+j;
                  bgImg.alpha = 0;
 
                  pageImgHolder.addChild(bgImg);
                 _oLoader.addItem(PATH+'images/'+pageXML.PARENT[i].PAGE[j].@IMAGE, bgImg, {title:'page'+i+'img'+j})
 
                  trace(pageImgHolder.parent.name+'/'+bgImg.parent.name+'/'+bgImg.name+' = '+pageXML.PARENT[i].PAGE[j].@IMAGE);
                 }
             }
          }
      xmlLoaded = true;
    } 
}
private function onQueueComplete(evt:QueueLoaderEvent):void {
    trace("** "+evt.type);
    imgHolderLoaded = true;
 
    Preloader.instance.spinnerDone();
    startMovie();
 
    bgImgHolder_mc.turnOnImg(0, 0);
    //turns on image for page 0, subpage 0 (i have a very complicated architecture)
}